Skip to content

Commit a64f698

Browse files
committed
Make cmp_fast_path more robust
On my Mac I see this test fail quite consistently. This change makes it more resilient in systems with slower startup times, while still allowing faster systems to finish as soon as possible.
1 parent 40aaeb6 commit a64f698

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tests/integration.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,24 @@ mod cmp {
825825
.spawn()
826826
.unwrap();
827827

828-
std::thread::sleep(std::time::Duration::from_millis(100));
829-
830-
assert_eq!(child.try_wait().unwrap().unwrap().code(), Some(1));
828+
// Bound the runtime to a very short time that still allows for some resource
829+
// constraint to slow it down while also allowing very fast systems to exit as
830+
// early as possible.
831+
const MAX_TRIES: u8 = 50;
832+
for tries in 0..=MAX_TRIES {
833+
if tries == MAX_TRIES {
834+
panic!("cmp took too long to run, /dev/null optimization probably not working")
835+
}
836+
match child.try_wait() {
837+
Ok(Some(status)) => {
838+
assert_eq!(status.code(), Some(1));
839+
break;
840+
}
841+
Ok(None) => (),
842+
Err(e) => panic!("{e:#?}"),
843+
}
844+
std::thread::sleep(std::time::Duration::from_millis(10));
845+
}
831846

832847
// Two stdins should be equal
833848
let mut cmd = cargo_bin_cmd!("diffutils");

0 commit comments

Comments
 (0)