@@ -951,21 +951,23 @@ mod tests {
951
951
#[ test]
952
952
fn test_last_24_hours_filter ( ) {
953
953
let filter = ResolvedTimestampFilter :: Last24Hours ;
954
- let now = Timestamp :: now ( ) ;
954
+
955
+ // Note: this test doesn't attempt to test close to the limits, because it can become
956
+ // flaky with slow execution time. This is also why we are calling `Timestamp::now()` again
957
+ // for each assert.
955
958
956
959
// Should accept timestamps within the last 24 hours
957
- assert ! ( filter. apply( now) ) ;
958
- assert ! ( filter. apply( now. checked_sub( 1 . hours( ) ) . unwrap( ) ) ) ;
959
- assert ! ( filter. apply( now. checked_sub( 12 . hours( ) ) . unwrap( ) ) ) ;
960
- assert ! ( filter. apply( now. checked_sub( 23 . hours( ) ) . unwrap( ) ) ) ;
960
+ assert ! ( filter. apply( Timestamp :: now( ) ) ) ;
961
+ assert ! ( filter. apply( Timestamp :: now( ) . checked_sub( 1 . hours( ) ) . unwrap( ) ) ) ;
962
+ assert ! ( filter. apply( Timestamp :: now( ) . checked_sub( 12 . hours( ) ) . unwrap( ) ) ) ;
963
+ assert ! ( filter. apply( Timestamp :: now( ) . checked_sub( 23 . hours( ) ) . unwrap( ) ) ) ;
961
964
962
965
// Should reject timestamps older than 24 hours
963
- assert ! ( !filter. apply( now. checked_sub( 25 . hours( ) ) . unwrap( ) ) ) ;
964
- assert ! ( !filter. apply( now. checked_sub( 48 . hours( ) ) . unwrap( ) ) ) ;
966
+ assert ! ( !filter. apply( Timestamp :: now( ) . checked_sub( 25 . hours( ) ) . unwrap( ) ) ) ;
967
+ assert ! ( !filter. apply( Timestamp :: now( ) . checked_sub( 48 . hours( ) ) . unwrap( ) ) ) ;
965
968
966
969
// Should reject future timestamps
967
- assert ! ( !filter. apply( now. checked_add( 1 . seconds( ) ) . unwrap( ) ) ) ;
968
- assert ! ( !filter. apply( now. checked_add( 1 . hours( ) ) . unwrap( ) ) ) ;
970
+ assert ! ( !filter. apply( Timestamp :: now( ) . checked_add( 1 . hours( ) ) . unwrap( ) ) ) ;
969
971
}
970
972
971
973
#[ test]
0 commit comments