From 8de22575cdc2c05c034c200ba4050f992dc0f280 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 19 Feb 2020 02:41:53 +0000 Subject: [PATCH] Tests: Use delta comparison in `test_site_dates_are_gmt()` to avoid race conditions. See #40364. git-svn-id: https://develop.svn.wordpress.org/trunk@47313 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/multisite/site.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 5afc0adf73..508cbd1319 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -405,11 +405,11 @@ if ( is_multisite() ) : wpmu_update_blogs_date(); + $blog = get_site( get_current_blog_id() ); + $current_time = time(); + // Compare the update time with the current time, allow delta < 2. - $blog = get_site( get_current_blog_id() ); - $current_time = time(); - $time_difference = $current_time - strtotime( $blog->last_updated ); - $this->assertLessThan( 2, $time_difference ); + $this->assertEquals( $current_time, strtotime( $blog->last_updated ), 'The dates should be equal', 2 ); } /** @@ -1766,16 +1766,16 @@ if ( is_multisite() ) : $this->assertInternalType( 'integer', $site_id ); $site = get_site( $site_id ); - $this->assertSame( $first_date, $site->registered ); - $this->assertSame( $first_date, $site->last_updated ); + $this->assertSame( strtotime( $first_date ), strtotime( $site->registered ), 'The dates should be equal', 2 ); + $this->assertSame( strtotime( $first_date ), strtotime( $site->last_updated ), 'The dates should be equal', 2 ); $second_date = current_time( 'mysql', true ); $site_id = wp_update_site( $site_id, array() ); $this->assertInternalType( 'integer', $site_id ); $site = get_site( $site_id ); - $this->assertSame( $first_date, $site->registered ); - $this->assertSame( $second_date, $site->last_updated ); + $this->assertSame( strtotime( $first_date ), strtotime( $site->registered ), 'The dates should be equal', 2 ); + $this->assertSame( strtotime( $second_date ), strtotime( $site->last_updated ), 'The dates should be equal', 2 ); } /**