From: Aaron Schulz Date: Tue, 12 Jun 2018 01:32:19 +0000 (-0700) Subject: Fix flaky MessageBlobStoreTest assertion failures X-Git-Tag: 1.31.2~34 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=25d4f7ecfaaf0eacbef9666c62d0152bbf27db2b Fix flaky MessageBlobStoreTest assertion failures Bug: T176097 Change-Id: I0f1e9a6a73bb5b2bc54ee400c5710055e992c3f1 (cherry picked from commit 46a43d8187a1aa1a7702bbfec2a3c5e20df4435a) --- diff --git a/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php b/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php index 4d98773890..7eb0944126 100644 --- a/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php +++ b/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php @@ -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' );