Skip to content

Commit b9b908f

Browse files
committed
Make a time test less flaky
This test was failing periodically on windows and other platforms, and in debugging the issue locally I've found that the previous test was failing at the assertion `ns0 <= ns1`. Upon inspecting the values, the two numbers were very close to one another, but off by a little bit. I believe that this is because `precise_time_s` goes from `u64` -> `f64` and then we go again back to `u64` for the assertion. This conversion is a lossy one that's not always guaranteed to succeed, so instead I've changed the test to only compare against u64 instances.
1 parent 2ee72ba commit b9b908f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/libextra/time.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,18 +1005,17 @@ mod tests {
10051005

10061006
fn test_precise_time() {
10071007
let s0 = precise_time_s();
1008-
let ns1 = precise_time_ns();
1009-
10101008
debug!("s0={} sec", f64::to_str_digits(s0, 9u));
10111009
assert!(s0 > 0.);
1012-
let ns0 = (s0 * 1000000000.) as u64;
1013-
debug!("ns0={:?} ns", ns0);
10141010

1015-
debug!("ns1={:?} ns", ns0);
1011+
let ns0 = precise_time_ns();
1012+
let ns1 = precise_time_ns();
1013+
debug!("ns0={:?} ns", ns0);
1014+
debug!("ns1={:?} ns", ns1);
10161015
assert!(ns1 >= ns0);
10171016

10181017
let ns2 = precise_time_ns();
1019-
debug!("ns2={:?} ns", ns0);
1018+
debug!("ns2={:?} ns", ns2);
10201019
assert!(ns2 >= ns1);
10211020
}
10221021

0 commit comments

Comments
 (0)