File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments