Make WordPress Core

Changeset 52587 for branches/5.1


Ignore:
Timestamp:
01/17/2022 01:47:45 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Fix race conditions in current_time() tests.

  • Restore default timezone before performing assertions to avoid affecting other tests in case of failure.
  • Use delta comparison for timestamps to avoid race conditions.

Props SergeyBiryukov, desrosj.
Merges [45857] to the 5.1 branch.
Fixes #45821.

Location:
branches/5.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.1

  • branches/5.1/tests/phpunit/tests/date/currentTime.php

    r43594 r52587  
    1515
    1616        date_default_timezone_set( $timezone_string );
    17         $this->assertEquals( gmdate( $format ), current_time( $format, true ) );
    18         $this->assertEquals( $datetime->format( $format ), current_time( $format ) );
     17
     18        $current_time_custom_timezone_gmt = current_time( $format, true );
     19        $current_time_custom_timezone     = current_time( $format );
    1920
    2021        date_default_timezone_set( 'UTC' );
    21         $this->assertEquals( gmdate( $format ), current_time( $format, true ) );
    22         $this->assertEquals( $datetime->format( $format ), current_time( $format ) );
     22
     23        $current_time_gmt = current_time( $format, true );
     24        $current_time     = current_time( $format );
     25
     26        $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( $current_time_custom_timezone_gmt ), 'The dates should be equal', 2 );
     27        $this->assertEquals( strtotime( $datetime->format( $format ) ), strtotime( $current_time_custom_timezone ), 'The dates should be equal', 2 );
     28        $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( $current_time_gmt ), 'The dates should be equal', 2 );
     29        $this->assertEquals( strtotime( $datetime->format( $format ) ), strtotime( $current_time ), 'The dates should be equal', 2 );
    2330    }
    2431}
Note: See TracChangeset for help on using the changeset viewer.