Skip to content

Commit 2ee292f

Browse files
committed
Auto merge of #7042 - ehuss:no-global-rm-rf, r=alexcrichton
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.
2 parents a3ea135 + 0082290 commit 2ee292f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

tests/testsuite/support/paths.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ lazy_static! {
2828
}
2929

3030
path.push(CARGO_INTEGRATION_TEST_DIR);
31-
32-
path.rm_rf();
3331
path.mkdir_p();
34-
3532
path
3633
};
3734

@@ -62,7 +59,9 @@ pub fn init_root() -> TestIdGuard {
6259

6360
let guard = TestIdGuard { _private: () };
6461

65-
root().mkdir_p();
62+
let r = root();
63+
r.rm_rf();
64+
r.mkdir_p();
6665

6766
guard
6867
}

0 commit comments

Comments
 (0)