Skip to content

Commit aca8bae

Browse files
committed
Fix flaky linking_interrupted test.
1 parent 8ad2196 commit aca8bae

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

tests/testsuite/freshness.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,8 @@ LLVM version: 9.0
23162316
fn linking_interrupted() {
23172317
// Interrupt during the linking phase shouldn't leave test executable as "fresh".
23182318

2319+
// This is used to detect when linking starts, then to pause the linker so
2320+
// that the test can kill cargo.
23192321
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
23202322
let addr = listener.local_addr().unwrap();
23212323

@@ -2367,6 +2369,8 @@ fn linking_interrupted() {
23672369
"CARGO_TARGET_{}_LINKER",
23682370
rustc_host().to_uppercase().replace('-', "_")
23692371
);
2372+
// NOTE: This assumes that the path to the linker is not in the
2373+
// fingerprint. But maybe it should be?
23702374
let mut cmd = p
23712375
.cargo("test --test t1 --no-run")
23722376
.env(&linker_env, linker.bin("linker"))
@@ -2381,8 +2385,21 @@ fn linking_interrupted() {
23812385

23822386
// Interrupt the child.
23832387
child.kill().unwrap();
2384-
// Note: rustc and the linker are still running, let them exit here.
2385-
conn.write(b"X").unwrap();
2388+
child.wait().unwrap();
2389+
// Note: rustc and the linker may still be running because we didn't kill
2390+
// the entire process group. Normally, when a user hits Ctrl-C, everything
2391+
// is killed. However, setting up process groups in a cross-platform test
2392+
// is a pain, and there's no easy way to know when everything has been
2393+
// killed. This write will tell them to exit, pretending that they died
2394+
// before finishing. Ignore the error, because (sometimes?) on Windows
2395+
// everything is already killed.
2396+
let _ = conn.write(b"X");
2397+
// Sleep a bit to allow rustc to clean up and exit. I have seen some race
2398+
// conditions on macOS where clang dies with `no such
2399+
// file...t1-HASH.rcgu.o`. I think what is happening is that the old rustc
2400+
// process is still running, and deletes the `*.o` files while the command
2401+
// below is trying to write them. Not sure if that is macOS-specific.
2402+
std::thread::sleep(std::time::Duration::new(2, 0));
23862403

23872404
// Build again, shouldn't be fresh.
23882405
p.cargo("test --test t1")

0 commit comments

Comments
 (0)