#38688 closed defect (bug) (fixed)
Tests Audit: some tests can fail when the date changes
Reported by: | pento | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 4.7 | Priority: | low |
Severity: | minor | Version: | |
Component: | Build/Test Tools | Keywords: | good-first-bug has-unit-tests |
Focuses: | Cc: |
Description
There are tests that generate the date twice - usually once for creating test data, then a second time for checking the expected output.
If the date changes between those two steps, the test will fail incorrectly.
Example: https://travis-ci.org/aaronjorbin/develop.wordpress/jobs/173767949
Attachments (2)
Change History (11)
#3
@
8 years ago
I've updated tests to call date once, while it's a bit difficult to reproduce locally i think it should be fine since by calling it once the date should be the very same. This is my first contribution to wordpress and done during Torino contribution day.
#4
@
8 years ago
- Keywords needs-unit-tests added; has-patch removed
Thanks for the patch, @xrmx! After checking this further today, after our talk at the Torino contributor evening, I don't think your patch completely fixes the issue.
The underlying problem is that 12 posts are created in the setUp()
method each time a test runs, and if the date ticks over to the next day in between the first post being created and the last post being created, then not all of the posts will have the same date.
In addition to the fixes in 0001-tests-call-date-once-per-test.patch, the post_date
property should be specified when creating the posts in the setUp()
method, and the same date can be used in each test instead of calling date()
.
#6
@
8 years ago
Updated patch to create posts and pages with the very same timestamp and use the very same timestamp for rendering comparison.
Call date once per test