Skip to content

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

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from

Conversation

danielrachi1
Copy link
Contributor

@danielrachi1 danielrachi1 commented Jul 11, 2025

Issue Addressed

Fixes #7735

Proposed Changes

Use tracing::subscriber::set_default to ensure that each test/thread has its own subscirber.

@danielrachi1 danielrachi1 requested a review from jxs as a code owner July 11, 2025 01:54
@danielrachi1 danielrachi1 changed the title Fix: Resolve RPC test failures Fix: RPC test failures Jul 11, 2025
@chong-he chong-he added test improvement Improve tests ready-for-review The code is ready for review labels Jul 11, 2025
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::try_new(level).unwrap())
.init();
});
Copy link
Member

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.
.with_env_filter(EnvFilter::try_new(level).unwrap())
.try_init()
.unwrap();
tracing::subscriber::set_default(
Copy link
Member

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?

@jimmygchen jimmygchen added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test improvement Improve tests waiting-on-author The reviewer has suggested changes and awaits thier implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants