Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

sp-runtime-interface-test: Fix flaky test #13770

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Mar 30, 2023

No description provided.

@bkchr bkchr added A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Mar 30, 2023
@bkchr bkchr requested review from ggwpez and a team March 30, 2023 14:19
@bkchr bkchr requested a review from koute as a code owner March 30, 2023 14:19
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Ran it 5 times in parallel on Thread 1 with 1000 reps and no failure. But also no on master…
PS: Will re-test with release.

@michalkucharczyk
Copy link
Contributor

Why the test was failing if run in parallel with other tests within single process?
Was tracing::subscriber::default overwritten by other test?

@michalkucharczyk
Copy link
Contributor

Why the test was failing if run in parallel with other tests within single process? Was tracing::subscriber::default overwritten by other test?

It should be thread_local, hm, idk...

@ggwpez
Copy link
Member

ggwpez commented Mar 30, 2023

It should be thread_local, hm, idk...

Yes that seems to cause it. Running on one thread is fine, but on multiple it errors:
while cargo test --offline --release -p sp-runtime-interface-test -- --test-threads 1; do true; done
vs
while cargo test --offline --release -p sp-runtime-interface-test -- --test-threads 10; do true; done
So basically the opposite of #10479 😆

@michalkucharczyk
Copy link
Contributor

michalkucharczyk commented Mar 30, 2023

I played with this a little. Seems that duplicating this line:

let _guard = tracing::subscriber::set_default(subscriber.clone());

works around the problem. The span also always contains 4 elements:

    "free_version_1",                              
    "blake2_256_version_1",
    "return_input_version_1",                                                                                          
    "malloc_version_1",

Without duplication the content seems to be random.

Does it look like some race-condition in registering the subscriber? If it is then we have hidden problem somewhere. Maybe not important, idk...

@michalkucharczyk
Copy link
Contributor

One more observation: on my local computer only this pair of tests is causing failures (50%):

cargo test -- test_return_data test_tracing

@bkchr
Copy link
Member Author

bkchr commented Mar 30, 2023

Does it look like some race-condition in registering the subscriber?

Yes this is the problem. I should have made the comment more "extended"

// Run in a different process to ensure that the `Span` is registered with our local
// `TracingSubscriber`.

This stuff is already tracked upstream tokio-rs/tracing#2436 tokio-rs/tracing#2411

We register the subcriber in a node early enough, at least I hope :D

let mut logger = LoggerBuilder::new(self.log_filters()?);
logger
.with_log_reloading(self.enable_log_reloading()?)
.with_detailed_output(self.detailed_log_output()?);
if let Some(tracing_targets) = self.tracing_targets()? {
let tracing_receiver = self.tracing_receiver()?;
logger.with_profiling(tracing_receiver, tracing_targets);
}
if self.disable_log_color()? {
logger.with_colors(false);
}
// Call hook for custom profiling setup.
logger_hook(&mut logger, config);
logger.init()?;

@bkchr bkchr merged commit ee38a52 into master Mar 30, 2023
@bkchr bkchr deleted the bkchr-fix-flaky-test-runtime-interface branch March 30, 2023 19:31
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants