Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TaskCenter][5/n] Introduces restate_core::test macro #2352

Merged
merged 4 commits into from
Nov 25, 2024
Merged

Conversation

AhmedSoliman
Copy link
Contributor

@AhmedSoliman AhmedSoliman commented Nov 22, 2024

Introduces a new macro that creates a default TaskCenter in tests. This should replace usage of tokio::test (the code is mostly based on it) and it provides access to TaskCenter::current() within the test code.

This also introduces a transitional type TestCoreEnv2, a clone of TestCoreEnv but without TaskCenter. After migration, this will be renamed to TestCoreEnv again.

Stack created with Sapling. Best reviewed with ReviewStack.

Copy link

github-actions bot commented Nov 22, 2024

Test Results

  5 files   -  2    5 suites   - 2   1m 50s ⏱️ - 2m 40s
 45 tests  -  2   44 ✅  -  2  1 💤 ±0  0 ❌ ±0 
113 runs   - 69  111 ✅  - 68  2 💤  - 1  0 ❌ ±0 

Results for commit 058539c. ± Comparison against base commit c19fcdf.

This pull request removes 2 tests.
dev.restate.sdktesting.tests.RunRetry ‑ withExhaustedAttempts(Client)
dev.restate.sdktesting.tests.RunRetry ‑ withSuccess(Client)

♻️ This comment has been updated with latest results.

@AhmedSoliman AhmedSoliman changed the title [TaskCenter] Stage 5 - test macro [TaskCenter][5/n] Introduces restate_core::test macro Nov 25, 2024
@AhmedSoliman AhmedSoliman marked this pull request as ready for review November 25, 2024 12:27
Copy link
Contributor

@tillrohrmann tillrohrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My knowledge about procedural macros is quite limited. So I guess my review is probably not the most profound. The changes look good and I like how our restate_core::test macro makes the test look a lot nicer :-) +1 for merging.

Comment on lines +978 to 979
// questionable.
RocksDbManager::get().shutdown().await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope: Why are we shutting the db manager in some test cases down and others not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In thoery, we should shutdown on every test that init()s rocksdb, but I think historically we only added the shutdown to tests that triggered segfaults on CI

// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

//! Some parts of this codebase were taken from https://github.com/tokio-rs/tokio/blob/master/tokio-macros/src/entry.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put the exact commit they were taken from instead of master?

- Adds `in_tc(&TaskCenter)` and `in_current_tc()` to scope a future to run in a task-center if it'll be dispatched as a task
- Introduces a root task (TaskId(0)) in TaskCenter that's used as a default parent/source of task context
- Removes unnecessary args from block_on, run_in_scope_sync. (some of those will be changed in future PRs)
- Introduces `Metadata::current()` and `Metadata::with_current(F)`
- Improvements to the future extensions (fixing root task context propagation)
- A round of removals of explicit task-center reference passing
- `try_set_global_metadata` is now an associated function

## Example

Before:
```rust
  task_center().spawn_child(
      TaskKind::RpcServer,
      "metadata-store-grpc",
      None,
      async move {
          net_util::run_hyper_server(
              &bind_address,
              service,
              "metadata-store-grpc",
              || health_status.update(MetadataServerStatus::Ready),
              || health_status.update(MetadataServerStatus::Unknown),
          )
          .await?;
          Ok(())
      },
  )?;
```

After:
```rust
  TaskCenter::spawn_child(TaskKind::RpcServer, "metadata-store-grpc", async move {
      net_util::run_hyper_server(
          &bind_address,
          service,
          "metadata-store-grpc",
          || health_status.update(MetadataServerStatus::Ready),
          || health_status.update(MetadataServerStatus::Unknown),
      )
      .await?;
      Ok(())
  })?;
```
Also, exercises `in_tc()` in some tests. Those will be swapped with `restate_core::test` in next PRs.

Example of impact:
```rust
  let bifrost = node_env
      .tc
      .run_in_scope(
          "bifrost init",
          None,
          Bifrost::init_in_memory(node_env.metadata.clone()),
      )
      .await;
```

Becomes:
```rust
  let bifrost = Bifrost::init_in_memory().in_tc(&node_env.tc).await;
```
Introduces a new macro that creates a default TaskCenter in tests. This should replace usage of `tokio::test` (the code is mostly based on it) and it provides access to `TaskCenter::current()` within the test code.

This also introduces a transitional type `TestCoreEnv2`, a clone of `TestCoreEnv` but without TaskCenter. After migration, this will be renamed to `TestCoreEnv` again.
@AhmedSoliman AhmedSoliman merged commit 058539c into main Nov 25, 2024
25 checks passed
@AhmedSoliman AhmedSoliman deleted the pr2352 branch November 25, 2024 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants