Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 4 years ago

#30336 closed defect (bug) (fixed)

microtime returning a string causes false test failures

Reported by: jorbin's profile jorbin Owned by: jorbin's profile jorbin
Milestone: 4.1 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Focuses: Cc:

Description

One of the assertions inside test_get_pages_cache (and possibly elsewhere) is that when deleting a post, the last_changed time in the posts cache is greater then it was before deleting it. The problem is that we are comparing microtime strings.

So you end up with things like:

Failed asserting that '0.01805200 1415892888' is greater than '0.99591600 1415892887'.

The problem is that it should be comparing 1415892888.018052 and 1415892887.995916 which would cause the test to pass.

Change History (5)

#1 @jorbin
10 years ago

  • Owner set to jorbin
  • Resolution set to fixed
  • Status changed from new to closed

In 30337:

When asserting microtime output as a number, make it a number

microtime is by default a string. Doing a greater then or less than check of that string is a bad idea since it uses the first part (the micro part of microtime) rather then the actual time. This adds a helper to convert microtime output into a float which we can then use to properly compare the output of microtime.

This fixes an intermittent test failure.

fixes #30336

#2 @johnbillion
7 years ago

In 40566:

When asserting microtime output as a number, make it a number

microtime is by default a string. Doing a greater then or less than check of that string is a bad idea since it uses the first part (the micro part of microtime) rather then the actual time. This adds a helper to convert microtime output into a float which we can then use to properly compare the output of microtime.

This fixes an intermittent test failure.

See #30336

Merges [30337] to the 4.0 branch.

#3 @SergeyBiryukov
4 years ago

In 47490:

When asserting microtime output as a number, make it a number.

microtime is by default a string. Doing a greater then or less than check of that string is a bad idea since it uses the first part (the micro part of microtime) rather then the actual time. This adds a helper to convert microtime output into a float which we can then use to properly compare the output of microtime.

This fixes an intermittent test failure.

Props jorbin.
Merges [30337] to the 3.9 branch.
See #30336, #49485.

#4 @SergeyBiryukov
4 years ago

In 47491:

When asserting microtime output as a number, make it a number.

microtime is by default a string. Doing a greater then or less than check of that string is a bad idea since it uses the first part (the micro part of microtime) rather then the actual time. This adds a helper to convert microtime output into a float which we can then use to properly compare the output of microtime.

This fixes an intermittent test failure.

Props jorbin.
Merges [30337] to the 3.8 branch.
See #30336, #49485.

#5 @SergeyBiryukov
4 years ago

In 47492:

When asserting microtime output as a number, make it a number.

microtime is by default a string. Doing a greater then or less than check of that string is a bad idea since it uses the first part (the micro part of microtime) rather then the actual time. This adds a helper to convert microtime output into a float which we can then use to properly compare the output of microtime.

This fixes an intermittent test failure.

Props jorbin.
Merges [30337] to the 3.7 branch.
See #30336, #49485.

Note: See TracTickets for help on using tickets.