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

[Merged by Bors] - Allow TaskExecutor to be used in async tests #3178

Closed
wants to merge 6 commits into from

Conversation

paulhauner
Copy link
Member

@paulhauner paulhauner commented May 13, 2022

Description

Since the TaskExecutor currently requires a Weak<Runtime>, it's impossible to use it in an async test where the Runtime is created outside our scope. Whilst we could create a new Runtime instance inside the async test, dropping that Runtime would cause a panic (you can't drop a Runtime in an async context).

To address this issue, this PR creates the enum Handle, which supports either:

  • A Weak<Runtime> (for use in our production code)
  • A Handle to a runtime (for use in testing)

In theory, there should be no change to the behaviour of our production code (beyond some slightly different descriptions in HTTP 500 errors), or even our tests. If there is no change, you might ask "why bother?". There are two PRs (#3070 and #3175) that are waiting on these fixes to introduce some new tests. Since we've added the EL to the BeaconChain (for the merge), we are now doing more async stuff in tests.

I've also added a RuntimeExecutor to the BeaconChainTestHarness. Whilst that's not immediately useful, it will become useful in the near future with all the new async testing.

Introduce harness to test harness

Thread task_executor into BeaconChain
@paulhauner paulhauner added the work-in-progress PR is a work-in-progress label May 13, 2022
@paulhauner paulhauner changed the title Unify the executor used in tests Allow TaskExecutor to be used in async tests May 15, 2022
@paulhauner paulhauner added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels May 16, 2022
@paulhauner paulhauner marked this pull request as ready for review May 16, 2022 03:26
Copy link
Member

@AgeManning AgeManning left a comment

Choose a reason for hiding this comment

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

Did a light review. Changes look fine to me

@@ -61,6 +61,7 @@ execution_layer = { path = "../execution_layer" }
sensitive_url = { path = "../../common/sensitive_url" }
superstruct = "0.5.0"
hex = "0.4.2"
exit-future = "0.2.0"
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this guy?

Copy link
Member Author

Choose a reason for hiding this comment

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

We use him in beacon_chain::test_utils.

Copy link
Member

Choose a reason for hiding this comment

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

If this is just testing? Can it be a dev-dep then?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just for testing, but it's not hidden behind a #[test] compilation flag so it must be a major dependency. We can't hide it behind a #[test] flag since it's used across multiple crates and Cargo doesn't play nicely with that.

Copy link
Member

@macladson macladson left a comment

Choose a reason for hiding this comment

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

Love it! Very clean.
Only suggestion is a single character that could be added to a comment

common/task_executor/src/test_utils.rs Outdated Show resolved Hide resolved
Co-authored-by: Mac L <mjladson@pm.me>
@paulhauner
Copy link
Member Author

Thanks for the reviews!

bors r+

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels May 16, 2022
bors bot pushed a commit that referenced this pull request May 16, 2022
# Description

Since the `TaskExecutor` currently requires a `Weak<Runtime>`, it's impossible to use it in an async test where the `Runtime` is created outside our scope. Whilst we *could* create a new `Runtime` instance inside the async test, dropping that `Runtime` would cause a panic (you can't drop a `Runtime` in an async context).

To address this issue, this PR creates the `enum Handle`, which supports either:

- A `Weak<Runtime>` (for use in our production code)
- A `Handle` to a runtime (for use in testing)

In theory, there should be no change to the behaviour of our production code (beyond some slightly different descriptions in HTTP 500 errors), or even our tests. If there is no change, you might ask *"why bother?"*. There are two PRs (#3070 and #3175) that are waiting on these fixes to introduce some new tests. Since we've added the EL to the `BeaconChain` (for the merge), we are now doing more async stuff in tests.

I've also added a `RuntimeExecutor` to the `BeaconChainTestHarness`. Whilst that's not immediately useful, it will become useful in the near future with all the new async testing.
@bors bors bot changed the title Allow TaskExecutor to be used in async tests [Merged by Bors] - Allow TaskExecutor to be used in async tests May 16, 2022
@bors bors bot closed this May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants