Skip to content

Commit ee035f2

Browse files
authored
Merge pull request #506 from gcomte/fix/timing-dependent-test
Replace absolute timing assertion with relative comparison
2 parents a33d7ed + 58540ba commit ee035f2

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/currency/fiat.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,19 @@ mod tests {
9898
fn test_exchange_rate_caching() {
9999
let start = Instant::now();
100100

101-
// First call should take a while.
101+
// First call fetches from the API.
102102
let btc_value = Fiat::USD.btc_value();
103-
let elapsed_first_call = start.elapsed().as_micros();
103+
let elapsed_first_call = start.elapsed();
104104
assert!(btc_value > 0.0);
105-
assert!(elapsed_first_call > 1000);
106105

107-
// Second call should be fast (even when looking up another fiat currency).
106+
// Second call should use cached data and be much faster.
107+
let start2 = Instant::now();
108108
let btc_value = Fiat::EUR.btc_value();
109+
let elapsed_second_call = start2.elapsed();
109110
assert!(btc_value > 0.0);
110-
assert!(start.elapsed().as_micros() - elapsed_first_call < 1000);
111+
assert!(
112+
elapsed_second_call < elapsed_first_call / 10,
113+
"Second call ({elapsed_second_call:?}) should be much faster than first ({elapsed_first_call:?})"
114+
);
111115
}
112116
}

0 commit comments

Comments
 (0)