Skip to content

Commit f66ad85

Browse files
authored
Merge pull request #152 from kov/cmp_fast_path
cmp_fast_path test improvements
2 parents de9bf94 + 7ddc6c6 commit f66ad85

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

tests/integration.rs

Lines changed: 19 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");
@@ -864,6 +879,7 @@ mod cmp {
864879
let mut cmd = cargo_bin_cmd!("diffutils");
865880
cmd.arg("cmp");
866881
cmd.arg(&a_path).arg(&b_path);
882+
cmd.env("LC_ALL", "en_US");
867883
cmd.assert()
868884
.code(predicate::eq(1))
869885
.failure()

0 commit comments

Comments
 (0)