Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#38688 closed defect (bug) (fixed)

Tests Audit: some tests can fail when the date changes

Reported by: pento's profile pento Owned by: johnbillion's profile 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)

0001-tests-call-date-once-per-test.patch (4.7 KB) - added by xrmx 8 years ago.
Call date once per test
38688.patch (6.8 KB) - added by xrmx 8 years ago.
updated patch

Download all attachments as: .zip

Change History (11)

#1 @pento
8 years ago

  • Keywords good-first-bug added

@xrmx
8 years ago

Call date once per test

#2 @xrmx
8 years ago

  • Keywords has-patch added; needs-patch removed

#3 @xrmx
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 @johnbillion
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().

#5 @xrmx
8 years ago

@johnbillion thanks for the hints, will update the patch next week.

@xrmx
8 years ago

updated patch

#6 @xrmx
8 years ago

Updated patch to create posts and pages with the very same timestamp and use the very same timestamp for rendering comparison.

#7 @johnbillion
8 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed
  • Owner set to johnbillion
  • Status changed from new to reviewing

#8 @johnbillion
8 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 39363:

Build/Test Tools: When testing the output of wp_list_pages(), use a known and fixed date for each post so the tests don't fail when the date changes between the beginning and end of a test.

Props xrmx
Fixes #38688

#9 @netweb
8 years ago

  • Milestone changed from Future Release to 4.7
Note: See TracTickets for help on using tickets.