From d14e829833f4749a70fe999135426c842b98c9db Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Fri, 28 Feb 2025 17:19:52 +0700 Subject: [PATCH] dev - Fix the flaky test in WC_Payments_Incentives_Service_Test (#10472) --- ...dev-fix-unstable-test-WC_Payments_Incentives_Service_Test | 5 +++++ tests/unit/test-class-wc-payments-incentives-service.php | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/dev-fix-unstable-test-WC_Payments_Incentives_Service_Test diff --git a/changelog/dev-fix-unstable-test-WC_Payments_Incentives_Service_Test b/changelog/dev-fix-unstable-test-WC_Payments_Incentives_Service_Test new file mode 100644 index 00000000000..49b420d9920 --- /dev/null +++ b/changelog/dev-fix-unstable-test-WC_Payments_Incentives_Service_Test @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: Fix the flaky tests due to using PHP time() in production vs test. + + diff --git a/tests/unit/test-class-wc-payments-incentives-service.php b/tests/unit/test-class-wc-payments-incentives-service.php index 9c8921289ab..9b12a949853 100644 --- a/tests/unit/test-class-wc-payments-incentives-service.php +++ b/tests/unit/test-class-wc-payments-incentives-service.php @@ -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; },