Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#38688 closed defect (bug) (fixed)

Tests Audit: some tests can fail when the date changes

Reported by: pento Owned by: johnbillion
Priority: low Milestone: 4.7
Component: Build/Test Tools Version:
Severity: minor Keywords: good-first-bug has-unit-tests
Cc: Focuses:

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 10 years ago.
Call date once per test
38688.patch​ (6.8 KB ) - added by xrmx 10 years ago.
updated patch

Download all attachments as: .zip

Change History (11)

#1 @pento
10 years ago

  • Keywords good-first-bug added

#2 @xrmx
10 years ago

  • Keywords has-patch added; needs-patch removed

#3 @xrmx
10 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
10 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
10 years ago

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

@xrmx
10 years ago

updated patch

#6 @xrmx
10 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
10 years ago

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

#8 @johnbillion
10 years ago

  • Resolution → fixed
  • Status reviewing → 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
10 years ago

  • Milestone Future Release → 4.7
Note: See TracTickets for help on using tickets.