-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix nonconcurrent tests #6900
Fix nonconcurrent tests #6900
Conversation
r? @ehuss (rust_highfive has picked a reviewer for you, use r? to override) |
8ec2751
to
c11c127
Compare
c11c127
to
2520bcf
Compare
Ping @ehuss |
Thanks for the PR! I don't think we can use backtraces to detect the current test, though. For example, on mac it runs about 5 times slower than normal. Would you be willing to try a solution that involves creating a new proc-macro attribute? I think this should work: Create a new |
dbc2d36
to
2a7e916
Compare
Done. I've put all the attribute changes in a separate commit for the reviewer's benefit. |
Would it be possible to keep the attribute short, like |
I wanted to keep the proc_macro hygenic. If you don't think that's useful, that can be done.
This is possible but it's a pretty significant rewrite of what I've done so far for IMO very little gain. Are you worried about the perf of the Mutex? |
☔ The latest upstream changes (presumably #6883) made this pull request unmergeable. Please resolve the merge conflicts. |
I don't know what this means here. I'm not sure how injecting a call to an init function should affect hygene.
Well, this as-is doesn't work. I'm not sure, but it looks to have some race conditions. I would lean towards a simple solution, more analogous to traditional test suite "setup" functions, that gets run before the test starts. |
The init function is not defined by the proc macro, so if you don't pass in the path to the init function, the macro is just making up the path out of thin air, which may or may not be imported at the place the function is defined.
I think it works fine, and there's no opportunity for a race condition because mostly everything is thread-local. The tests are currently failing because I think I changed some |
@ehuss I answered your questions. |
I would still prefer a simpler attribute as explained above. Also, I don't think we can't switch Cargo to a workspace because it is inside another workspace in rust-lang. EDIT: We'll also need to figure out some way to publish this new package, we can't have a path-only dependency. My preference would be to relax this restriction, but it'll be some work. |
113ff07
to
6a2fecd
Compare
Pushed changes. If the current code is acceptable I'd prefer a swift review since this bitrots pretty quickly. |
sed -i 's/^#\[test\]/#[cargo_test]/' $(rg -l '^#\[test\]') Manual fixes: * proc_macro::proc_macro_doctest
6a2fecd
to
a8c22ca
Compare
Thanks! |
📌 Commit a8c22ca has been approved by |
Fix nonconcurrent tests The cargo testsuite relies on a clean test “root” for every test (i.e. `#[test]`-annotated function). It relied on the `test` crate's behavior to spawn a new thread for each test, which isn't done when tests aren't run concurrently, breaking the test suite. In this PR, I'm using backtraces to figure out which test is being run, which is much more robust. I also cleaned up the root initialization logic so that it no longer recursive calls the `init` function. Fixes #6746
☀️ Test successful - checks-travis, status-appveyor |
I am seeing |
Can you run it again with |
Looks like delling my |
Update cargo Update cargo 19 commits in 545f354259be4e9745ea00a524c0e4c51df01aa6..807429e1b6da4e2ec52488ef2f59e77068c31e1f 2019-05-23 17:45:30 +0000 to 2019-06-11 14:06:10 +0000 - Stabilize publish-lockfile. (rust-lang/cargo#7026) - change package cache lock message (rust-lang/cargo#7029) - Fix documenting an example. (rust-lang/cargo#7023) - Fix nonconcurrent tests (rust-lang/cargo#6900) - Update git2 crates for libgit2 0.28 (rust-lang/cargo#7018) - fix bunch of clippy warnings (rust-lang/cargo#7019) - Ignore remap-path-prefix in metadata hash. (rust-lang/cargo#6966) - Don't synthesize feature diretives for non-optional deps (rust-lang/cargo#7010) - Handle pipelined tests of libraries (rust-lang/cargo#7008) - Import the cargo-vendor subcommand into Cargo (rust-lang/cargo#6869) - Remove unnecessary outlives bounds (rust-lang/cargo#7000) - Catch filename output collisions in rustdoc. (rust-lang/cargo#6998) - the testing SAT solver was messed up by a refactor (rust-lang/cargo#6995) - Add some hints to the docs for `cfg()` targets (rust-lang/cargo#6990) - Test the Resolver against the varisat Library (rust-lang/cargo#6980) - Update changelog. (rust-lang/cargo#6984) - Update cache-messages tracking issue. (rust-lang/cargo#6987) - zsh: Add --all-targets option to cargo-check and cargo-build (rust-lang/cargo#6985) - Fix typo (rust-lang/cargo#6982)
Update cargo Update cargo 19 commits in 545f354259be4e9745ea00a524c0e4c51df01aa6..807429e1b6da4e2ec52488ef2f59e77068c31e1f 2019-05-23 17:45:30 +0000 to 2019-06-11 14:06:10 +0000 - Stabilize publish-lockfile. (rust-lang/cargo#7026) - change package cache lock message (rust-lang/cargo#7029) - Fix documenting an example. (rust-lang/cargo#7023) - Fix nonconcurrent tests (rust-lang/cargo#6900) - Update git2 crates for libgit2 0.28 (rust-lang/cargo#7018) - fix bunch of clippy warnings (rust-lang/cargo#7019) - Ignore remap-path-prefix in metadata hash. (rust-lang/cargo#6966) - Don't synthesize feature diretives for non-optional deps (rust-lang/cargo#7010) - Handle pipelined tests of libraries (rust-lang/cargo#7008) - Import the cargo-vendor subcommand into Cargo (rust-lang/cargo#6869) - Remove unnecessary outlives bounds (rust-lang/cargo#7000) - Catch filename output collisions in rustdoc. (rust-lang/cargo#6998) - the testing SAT solver was messed up by a refactor (rust-lang/cargo#6995) - Add some hints to the docs for `cfg()` targets (rust-lang/cargo#6990) - Test the Resolver against the varisat Library (rust-lang/cargo#6980) - Update changelog. (rust-lang/cargo#6984) - Update cache-messages tracking issue. (rust-lang/cargo#6987) - zsh: Add --all-targets option to cargo-check and cargo-build (rust-lang/cargo#6985) - Fix typo (rust-lang/cargo#6982)
@Eh2406 I'm having a hard time reproducing the issue you are seeing. I had a few questions:
|
Oh, I reproduced it! I think lowering down to 2 cpu's was the trick. I'll dig in a little more. |
Update cargo Update cargo 19 commits in 545f354259be4e9745ea00a524c0e4c51df01aa6..807429e1b6da4e2ec52488ef2f59e77068c31e1f 2019-05-23 17:45:30 +0000 to 2019-06-11 14:06:10 +0000 - Stabilize publish-lockfile. (rust-lang/cargo#7026) - change package cache lock message (rust-lang/cargo#7029) - Fix documenting an example. (rust-lang/cargo#7023) - Fix nonconcurrent tests (rust-lang/cargo#6900) - Update git2 crates for libgit2 0.28 (rust-lang/cargo#7018) - fix bunch of clippy warnings (rust-lang/cargo#7019) - Ignore remap-path-prefix in metadata hash. (rust-lang/cargo#6966) - Don't synthesize feature diretives for non-optional deps (rust-lang/cargo#7010) - Handle pipelined tests of libraries (rust-lang/cargo#7008) - Import the cargo-vendor subcommand into Cargo (rust-lang/cargo#6869) - Remove unnecessary outlives bounds (rust-lang/cargo#7000) - Catch filename output collisions in rustdoc. (rust-lang/cargo#6998) - the testing SAT solver was messed up by a refactor (rust-lang/cargo#6995) - Add some hints to the docs for `cfg()` targets (rust-lang/cargo#6990) - Test the Resolver against the varisat Library (rust-lang/cargo#6980) - Update changelog. (rust-lang/cargo#6984) - Update cache-messages tracking issue. (rust-lang/cargo#6987) - zsh: Add --all-targets option to cargo-check and cargo-build (rust-lang/cargo#6985) - Fix typo (rust-lang/cargo#6982)
Revert test directory cleaning change. #6900 changed it so that the entire `cit` directory was cleaned once when tests started. Previously, each `t#` directory was deleted just before each test ran. This restores the old behavior due to problems on Windows. The problem is that the call to `rm_rf` would fail with various errors ("Not found", "directory not empty", etc.) if you run `cargo test` twice. The first panic would poison the lazy static initializer, causing all subsequent tests to fail. There are a variety of reasons deleting a file on Windows is difficult. My hypothesis in this case is that services like the indexing service and Defender swoop in and temporarily hold handles to files. This seems to be worse on slower systems, where presumably these services take longer to process all the files created by the test suite. It may also be related to how files are "marked for deletion" but are not immediately deleted. The solution here is to spread out the deletion over time, giving Windows more of an opportunity to release its handles. This is a poor solution, and should only help reduce the frequency, but not entirely fix it. I believe that this cannot be solved using `DeleteFileW`. There are more details at rust-lang/rust#29497, which is a long-standing problem that there are no good Rust implementations for recursively deleting a directory. An example of something that implements a "safe" delete is [Cygwin's unlink implementation](https://github.com/cygwin/cygwin/blob/ad101bcb0f55f0eb1a9f60187f949c3decd855e4/winsup/cygwin/syscalls.cc#L675-L1064). As you can see, it is quite complex. Of course our use case does not need to handle quite as many edge cases, but I think any implementation is going to be nontrivial, and require Windows-specific APIs not available in std. Note: Even before #6900 I still get a lot of errors on a slow VM (particularly "directory not empty"), with Defender and Indexing off. I'm not sure why. This PR should make it more bearable, though.
The cargo testsuite relies on a clean test “root” for every test (i.e.
#[test]
-annotated function). It relied on thetest
crate's behavior to spawn a new thread for each test, which isn't done when tests aren't run concurrently, breaking the test suite. In this PR, I'm using backtraces to figure out which test is being run, which is much more robust. I also cleaned up the root initialization logic so that it no longer recursive calls theinit
function.Fixes #6746