Skip to content

Commit

Permalink
dev - Fix flaky tests in WC_Payments_Incentives_Service_Test
Browse files Browse the repository at this point in the history
  • Loading branch information
htdat committed Feb 28, 2025
1 parent 4af3a1f commit cefae87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Fix the flaky tests due to using PHP time() in production vs test.


4 changes: 3 additions & 1 deletion tests/unit/test-class-wc-payments-incentives-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ function ( $value, $expiration ) {
$this->assertSame( 'yes', $value );

// Ensure the cache is set to expire in 90 days - 30 days = 60 days.
$this->assertSame( 60 * DAY_IN_SECONDS, $expiration );
$expected_expiration = 60 * DAY_IN_SECONDS;
// Allowing 5-second difference to avoid flaky tests due to time() precision.
$this->assertLessThanOrEqual( 5, abs( $expected_expiration - $expiration ), 'Expiration time should be within 5 second of expected value' );

return $value;
},
Expand Down

0 comments on commit cefae87

Please sign in to comment.