-
Notifications
You must be signed in to change notification settings - Fork 805
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
Conversation
Introduce harness to test harness Thread task_executor into BeaconChain
TaskExecutor
to be used in async
tests
There was a problem hiding this 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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
Co-authored-by: Mac L <[email protected]>
Thanks for the reviews! bors r+ |
# 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.
TaskExecutor
to be used in async
testsTaskExecutor
to be used in async
tests
Description
Since the
TaskExecutor
currently requires aWeak<Runtime>
, it's impossible to use it in an async test where theRuntime
is created outside our scope. Whilst we could create a newRuntime
instance inside the async test, dropping thatRuntime
would cause a panic (you can't drop aRuntime
in an async context).To address this issue, this PR creates the
enum Handle
, which supports either:Weak<Runtime>
(for use in our production code)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 theBeaconChainTestHarness
. Whilst that's not immediately useful, it will become useful in the near future with all the new async testing.