Skip to content

Commit aaa2ebd

Browse files
authored
Merge pull request #7327 from cakebaker/test_remove_sleep
test: remove `sleep` from tests
2 parents a2af5d6 + 1910da5 commit aaa2ebd

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

tests/by-util/test_test.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// spell-checker:ignore (words) egid euid pseudofloat
77

88
use crate::common::util::TestScenario;
9-
use std::thread::sleep;
109

1110
#[test]
1211
fn test_empty_test_equivalent_to_false() {
@@ -380,28 +379,28 @@ fn test_same_device_inode() {
380379
fn test_newer_file() {
381380
let scenario = TestScenario::new(util_name!());
382381

383-
scenario.fixtures.touch("regular_file");
384-
sleep(std::time::Duration::from_millis(100));
382+
let older_file = scenario.fixtures.make_file("older_file");
383+
older_file.set_modified(std::time::UNIX_EPOCH).unwrap();
385384
scenario.fixtures.touch("newer_file");
386385

387386
scenario
388387
.ucmd()
389-
.args(&["newer_file", "-nt", "regular_file"])
388+
.args(&["newer_file", "-nt", "older_file"])
390389
.succeeds();
391390

392391
scenario
393392
.ucmd()
394-
.args(&["regular_file", "-nt", "newer_file"])
393+
.args(&["older_file", "-nt", "newer_file"])
395394
.fails();
396395

397396
scenario
398397
.ucmd()
399-
.args(&["regular_file", "-ot", "newer_file"])
398+
.args(&["older_file", "-ot", "newer_file"])
400399
.succeeds();
401400

402401
scenario
403402
.ucmd()
404-
.args(&["newer_file", "-ot", "regular_file"])
403+
.args(&["newer_file", "-ot", "older_file"])
405404
.fails();
406405
}
407406

@@ -946,12 +945,15 @@ fn test_bracket_syntax_version() {
946945
fn test_file_N() {
947946
let scene = TestScenario::new(util_name!());
948947
let at = &scene.fixtures;
949-
scene.ucmd().args(&["-N", "regular_file"]).fails();
948+
949+
let f = at.make_file("file");
950+
f.set_modified(std::time::UNIX_EPOCH).unwrap();
951+
952+
scene.ucmd().args(&["-N", "file"]).fails();
950953
// The file will have different create/modified data
951954
// so, test -N will return 0
952-
sleep(std::time::Duration::from_millis(100));
953-
at.touch("regular_file");
954-
scene.ucmd().args(&["-N", "regular_file"]).succeeds();
955+
at.touch("file");
956+
scene.ucmd().args(&["-N", "file"]).succeeds();
955957
}
956958

957959
#[test]

0 commit comments

Comments
 (0)