Skip to content

Commit 0f9df98

Browse files
committed
Auto merge of #5488 - alexcrichton:Retry, r=matklad
Cop out on fixing a spurious test failure This commit cops out trying to fix `rename_with_link_search_path` by simply adding a loop on Windows to retry the operation that looks to need retrying.
2 parents d19e295 + 1759b30 commit 0f9df98

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/testsuite/build_script.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use std::env;
22
use std::fs::{self, File};
33
use std::io::prelude::*;
44
use std::path::PathBuf;
5+
use std::io;
6+
use std::thread;
7+
use std::time::Duration;
58

69
use cargo::util::paths::remove_dir_all;
710
use cargotest::{rustc_host, sleep_ms};
@@ -3821,7 +3824,28 @@ fn rename_with_link_search_path() {
38213824
let mut new = p2.root();
38223825
new.pop();
38233826
new.push("bar2");
3824-
fs::rename(p2.root(), &new).unwrap();
3827+
3828+
// For whatever reason on Windows right after we execute a binary it's very
3829+
// unlikely that we're able to successfully delete or rename that binary.
3830+
// It's not really clear why this is the case or if it's a bug in Cargo
3831+
// holding a handle open too long. In an effort to reduce the flakiness of
3832+
// this test though we throw this in a loop
3833+
//
3834+
// For some more information see #5481 and rust-lang/rust#48775
3835+
let mut i = 0;
3836+
loop {
3837+
let error = match fs::rename(p2.root(), &new) {
3838+
Ok(()) => break,
3839+
Err(e) => e,
3840+
};
3841+
i += 1;
3842+
if !cfg!(windows) || error.kind() != io::ErrorKind::PermissionDenied || i > 10 {
3843+
panic!("failed to rename: {}", error);
3844+
}
3845+
println!("assuming {} is spurious, waiting to try again", error);
3846+
thread::sleep(Duration::from_millis(100));
3847+
}
3848+
38253849
assert_that(
38263850
p2.cargo("run").cwd(&new),
38273851
execs().with_status(0).with_stderr(

0 commit comments

Comments
 (0)