Skip to content

Commit c4e19cc

Browse files
committed
Auto merge of #13811 - ehuss:remove-sleep-test, r=weihanglo
Update SleepTraker returns_in_order unit test This updates the `returns_in_order` SleepTracker unit test so that it is not so sensitive to how fast the system is running. Previously it assumed that the function calls would take less than a millisecond to finish, but that is not a valid assumption for a slow-running system. I have changed it to simplify the test, with the assumption that it takes less than 30 seconds for it to run, which should have a safety margin of a few orders of magnitude.
2 parents b60a155 + 06fb65e commit c4e19cc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/cargo/util/network/sleep.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,15 @@ impl<T> SleepTracker<T> {
9090
#[test]
9191
fn returns_in_order() {
9292
let mut s = SleepTracker::new();
93-
s.push(3, 3);
93+
s.push(30_000, 30_000);
9494
s.push(1, 1);
95-
s.push(6, 6);
96-
s.push(5, 5);
97-
s.push(2, 2);
98-
s.push(10000, 10000);
99-
assert_eq!(s.len(), 6);
100-
std::thread::sleep(Duration::from_millis(100));
101-
assert_eq!(s.to_retry(), &[1, 2, 3, 5, 6]);
95+
assert_eq!(s.len(), 2);
96+
std::thread::sleep(Duration::from_millis(2));
97+
assert_eq!(s.to_retry(), &[1]);
98+
assert!(s.to_retry().is_empty());
99+
let next = s.time_to_next().expect("should be next");
100+
assert!(
101+
next < Duration::from_millis(30_000),
102+
"{next:?} should be less than 30s"
103+
);
102104
}

0 commit comments

Comments
 (0)