Fix flaky MessageBlobStoreTest assertion failures
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 12 Jun 2018 01:32:19 +0000 (18:32 -0700)
committerReedy <reedy@wikimedia.org>
Sun, 17 Feb 2019 12:42:22 +0000 (12:42 +0000)
Bug: T176097
Change-Id: I0f1e9a6a73bb5b2bc54ee400c5710055e992c3f1
(cherry picked from commit 46a43d8187a1aa1a7702bbfec2a3c5e20df4435a)

tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php

index 4d98773..7eb0944 100644 (file)
@@ -26,8 +26,12 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase {
                $this->wanCache->expects( $this->any() )
                        ->method( 'makePurgeValue' )
                        ->will( $this->returnCallback( function ( $timestamp, $holdoff ) {
-                               // Disable holdoff as it messes with testing
-                               return WANObjectCache::PURGE_VAL_PREFIX . (float)$timestamp . ':0';
+                               // Disable holdoff as it messes with testing. Aside from a 0-second holdoff,
+                               // make sure that "time" passes between getMulti() check init and the set()
+                               // in recacheMessageBlob(). This especially matters for Windows clocks.
+                               $ts = (float)$timestamp - 0.0001;
+
+                               return WANObjectCache::PURGE_VAL_PREFIX . $ts . ':0';
                        } ) );
        }
 
@@ -202,12 +206,16 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase {
                        ->method( 'fetchMessage' )
                        ->will( $this->onConsecutiveCalls( 'First', 'Second' ) );
 
+               $now = microtime( true );
+               $this->wanCache->setMockTime( $now );
+
                $blob = $blobStore->getBlob( $module, 'en' );
                $this->assertEquals( '{"example":"First"}', $blob, 'Generated blob' );
 
                $blob = $blobStore->getBlob( $module, 'en' );
                $this->assertEquals( '{"example":"First"}', $blob, 'Cache-hit' );
 
+               $now += 1;
                $blobStore->clear();
 
                $blob = $blobStore->getBlob( $module, 'en' );