#38381 closed defect (bug) (fixed)
Race conditions in Tests_Date_I18n
Reported by: | pento | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 4.7 | Priority: | low |
Severity: | minor | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
All of the tests that generate the expected and actual values from date()
calls are subject to a race condition, where the time can tick to the next second between calls.
See this test job for an example of an inadvertent failure.
Attachments (2)
Change History (13)
#1
@
8 years ago
- Summary changed from Race conditions in `Tests_Date_I18n` to Race conditions in Tests_Date_I18n
#2
@
8 years ago
- Milestone changed from Future Release to 4.7
- Owner set to swissspidy
- Status changed from new to assigned
#4
follow-up:
↓ 5
@
8 years ago
To ensure consistent behaviour, the best option would be to get the output of time()
at the start of each test, then pass it to the date()
and date_i18n()
calls, to ensure they're both generating from the same timestamp.
#5
in reply to:
↑ 4
@
8 years ago
Replying to pento:
To ensure consistent behaviour, the best option would be to get the output of
time()
at the start of each test, then pass it to thedate()
anddate_i18n()
calls, to ensure they're both generating from the same timestamp.
But then I can't really test for the case where no timestamp is passed to the function. I mean, ideally we'd mock dates, but the delta comparison should work just as well.
#6
@
8 years ago
I think this'll be the first time we've ever used delta comparisons in our unit tests. :-)
Yah, let's go with it. Can you confirm that the $message
parameter isn't required before you commit? The PHPUnit Docs imply that it is.
#7
@
8 years ago
- Keywords commit added
Ah yeah you're right, the $message
comes before the $delta
. It's an empty string by default but I added a message in 38381.2.diff.
#9
@
8 years ago
Referencing here [39012] and [39013] follow up commits that were added to fix an issue with Daylight Savings Time ending in Europe, see https://wordpress.slack.com/archives/core/p1477789573011015
@pento Thanks for opening the issue! I just saw it today and realized how bad the tests were. Mind a review?