refactor(test): execute all #[rustup_macros::unit_test]
s within a tokio
context
#3868
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Split from #3803.
With this PR, all tests under the
#[rustup_macros::unit_test]
attribute now execute within atokio
runtime, eliminating the need of staticTRACER
andTRACE_RUNTIME
variables. Also, the setup oftracing
subscribers in bothbin
andtest
targets has also been unified, to prepare for the addition of anotherstderr
-oriented subscriber in #3803.Rationale
Currently, the
tracing
subscriber registration will fail if a tokio runtime is not present. To mitigate this problem, staticTRACER
andTRACE_RUNTIME
variables are added as an ad-hoc fallback if we're running a non-tokio unit test.rustup/src/test.rs
Lines 230 to 237 in 3ba08da
However, the fact that the subscriber state is global in tests has made some unnecessary complications especially WRT adding other
tracing
subscribers, such as thestderr
-oriented tracing subscriber proposed in #3803 (comment), which is bound to the localcurrentprocess:process()
context (see #3803 (comment)).I decided to go with local contexts all the way, and it did work. However, the main downside to this approach is that #2367 has to be reverted, since
run_inprocess()
callswith_runtime()
, and for the latter to correctly alterstatic PROCESS
in-process, atokio
runtime builder is required, which in this case will cause a "runtime-in-runtime" error once the builder is run.Fortunately, no obvious slowdown has been observed WRT our CI so far. Also, as now
main()
seems to be the only caller towith_runtime()
, this gets us closer to using#[tokio::main]
.