-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add ‘#[serial]’ tests (v2) #42684
Add ‘#[serial]’ tests (v2) #42684
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Perhaps a name like |
I think |
Ah, I didn’t understand how the feature gates work and the example I followed (#42219) is apparently a WIP. Looking at #42088, I need to gate this by:
(active, serial_tests, "1.19.0", Some(42684))
("serial", Normal, Gated(Stability::Unstable, "serial_tests", "the `#[serial]` attribute is an experimental feature", cfg_fn!(serial_tests))
Is this correct? Have I missed anything? I’ll try to get it done pronto, but if not, it will be about a week. Re: the name of the attribute itself, I can change that if |
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.
Few minor things. Overal code looks good to me.
src/libsyntax/test.rs
Outdated
@@ -52,7 +52,8 @@ struct Test { | |||
path: Vec<Ident> , | |||
bench: bool, | |||
ignore: bool, | |||
should_panic: ShouldPanic | |||
should_panic: ShouldPanic, | |||
serial: bool |
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.
Please end the line with a comma, so there is less noise when new fields get added.
src/libsyntax/test.rs
Outdated
@@ -133,7 +134,8 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { | |||
path: self.cx.path.clone(), | |||
bench: is_bench_fn(&self.cx, &i), | |||
ignore: is_ignored(&i), | |||
should_panic: should_panic(&i, &self.cx) | |||
should_panic: should_panic(&i, &self.cx), | |||
serial: is_serial(&i) |
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.
Same here
src/libtest/lib.rs
Outdated
name: StaticTestName("first"), | ||
ignore: false, | ||
should_panic: ShouldPanic::No, | ||
serial: true |
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.
Same here
src/libtest/lib.rs
Outdated
name: StaticTestName("second"), | ||
ignore: false, | ||
should_panic: ShouldPanic::No, | ||
serial: true |
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.
Same here
src/libtest/lib.rs
Outdated
TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), | ||
TestEvent::TeTimeout(_) => panic!("timeout"), | ||
TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => | ||
panic!("result not okay"), |
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.
Please print the result too. Eg
panic!("result not okay: {:?}", result),
src/libtest/lib.rs
Outdated
TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), | ||
TestEvent::TeTimeout(_) => panic!("timeout"), | ||
TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => | ||
panic!("result not okay"), |
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.
Same printing thing here.
☔ The latest upstream changes (presumably #42664) made this pull request unmergeable. Please resolve the merge conflicts. |
@shivjm I believe this is waiting on some changes from you and a rebase. Let us know if we can help in any way! Feel free to ping me on IRC (simulacrum). |
Sorry, been out of town and then busy catching up! I’ve rebased the PR and (I hope) fixed the issues @bjorn3 pointed out (thanks!). Next up, need to implement the feature gate. I’ll ask for help on IRC. |
I’ve added the |
The requirement for an entry has been removed. You can add one (with meaningful content) if you want to, if not, a stub will be generated automatically. |
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.
Lgtm when the trailing newline is added.
#[serial] //~ ERROR serial tests are currently unstable | ||
fn in_serial() { | ||
assert!(true); | ||
} |
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.
Please add a trailing newline.
Done, thanks! |
Thanks for the patch. This probably needs more discussion before landing. This is a thing that we've declined to do for many years. |
cc @nrc |
☔ The latest upstream changes (presumably #42964) made this pull request unmergeable. Please resolve the merge conflicts. |
Is there anything I can do to help? |
☔ The latest upstream changes (presumably #42727) made this pull request unmergeable. Please resolve the merge conflicts. |
@brson do you have links to previous discussion or could you summarise here please? My opinion (uninformed by previous discussion) is that this is something I've wanted personally and I don't see why we should not support it (as long as it is feature gated etc.) being its own attribute feels kind of wrong (I'd prefer to attach it to |
Discussed at the dev-tools meeting today, this problem can be solved today using a mutex (I filed #43155 to document that). Given that this solution feels somewhat ad hoc and there is workaround, we would prefer to punt on adding this in favour of custom test runners or some other long-term solution. Thanks for the PR @shivjm and sorry to close it out after your work. |
Alright. Thanks for letting me know.
|
@nrc I don't see why this shouldn't be implemented in the test framework. The mutex work around seems to have some catches, and is non-trivial to get right. |
For everyone getting to this point: This solution is also implemented in a separate crate now: |
(Fixed version of #42626; sorry for the noise.)
This PR adds a
#[serial]
attribute that marks tests that should be executed one-by-one rather than concurrently (per #33519).I’ve confirmed that the libtest and tidy tests pass. I wasn’t able to run the full suite as a lot of the run_make tests seem to fail on my Windows system, but everything passed up to that point.
Rust (and PR!) newbie here, so please do let me know if I’m doing something poorly or incorrectly!