Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
87 stars 32 forks source link

Unit test`WC_Subscriptions_Test::test_calculate_trial_end_date` is intermittently failing because it has an overly sensitive time assertion #98

Open mattallan opened 2 years ago

mattallan commented 2 years ago

Description

One of our unit tests sometimes passes or fails with the following in result:

1) WC_Subscriptions_Test::test_calculate_trial_end_date
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'2022-02-17 05:28:33'
+'2022-02-17 05:28:34'

The 1 second off issue is caused by the unit test storing a value for $now = time(); before creating a new subscription. The test then compares $now + 1 month with the subscriptions start time + 1 month which can sometimes be different.

I think we should update this unit test to not store time() and instead use the start time on the subscription.

haszari commented 1 year ago

Updated the title to make the problem clear.

We could also use a fuzzy assertion (month +/- 5 mins might be fine).