Make WordPress Core

Changeset 47490


Ignore:
Timestamp:
03/22/2020 02:43:22 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
branches/3.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.9

  • branches/3.9/tests/phpunit/includes/testcase.php

    r47329 r47490  
    166166        }
    167167    }
    168    
     168
    169169    function flush_cache() {
    170170        global $wp_object_cache;
     
    506506        return $files;
    507507    }
     508
     509    /**
     510     * Helper to Convert a microtime string into a float
     511     */
     512    protected function _microtime_to_float($microtime ){
     513        $time_array = explode( ' ', $microtime );
     514        return array_sum( $time_array );
     515    }
    508516}
  • branches/3.9/tests/phpunit/tests/post/getPages.php

    r27767 r47490  
    8080        // This should bump last_changed.
    8181        wp_delete_post( $pages[0]->ID );
    82         $this->assertGreaterThan( $last_changed, wp_cache_get( 'last_changed', 'posts' ) );
     82        $old_changed_float = $this->_microtime_to_float( $last_changed );
     83        $new_changed_float = $this->_microtime_to_float( wp_cache_get( 'last_changed', 'posts' ) );
     84        $this->assertGreaterThan( $old_changed_float, $new_changed_float );
    8385
    8486        $num_queries = $wpdb->num_queries;
Note: See TracChangeset for help on using the changeset viewer.