-
Notifications
You must be signed in to change notification settings - Fork 889
Fix: RPC test failures #7734
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
base: unstable
Are you sure you want to change the base?
Fix: RPC test failures #7734
Conversation
tracing_subscriber::fmt() | ||
.with_env_filter(EnvFilter::try_new(level).unwrap()) | ||
.init(); | ||
}); |
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.
Thanks for the PR!
I noticed a little limitation with this approach though - once tracing is initialised globally (via init
) with a specific log level (e.g., "info"), any subsequent tests that try to use a different level (e.g., "debug") won't see their preferred level applied, and it would not be obvious why debug logs aren't showing.
I think we could try to create test-local subscribers using the tracing::subscriber::set_default
method or something similar, which returns a guard that unregisters the subscriber when dropped.
Some RPC tests were failing intermittently due to a race condition when initializing the global tracing subscriber. This could cause a panic if multiple tests attempted to initialize the subscriber simultaneously. This change prevents the race condition, making the tests more stable.
Use `tracing::subscriber::set_default` for setting the subscriber on a thread/test. Using `std::sync::Once` would cause any subsequent tests that try to use a different level won't see their preferred level applied, and it would not be obvious why debug logs aren't showing.
c936b1b
to
d86c218
Compare
.with_env_filter(EnvFilter::try_new(level).unwrap()) | ||
.try_init() | ||
.unwrap(); | ||
tracing::subscriber::set_default( |
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.
I think the subscriber is immediately dropped because the return value is not used here. Have you tested this locally?
Issue Addressed
Fixes #7735
Proposed Changes
Use
tracing::subscriber::set_default
to ensure that each test/thread has its own subscirber.