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: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/%22%24encUrl/%27%40script%40/ecrire/%40%20%27entree_nom_pseudo_1%27%20=%3E%20%27%28Your%20name%20or%20alias%29%27%2C%20%27entree_nom_pseudo_2%27%20=%3E%20%27Name%20or%20alias%27%2C%20%27entree_nom_site%27%20=%3E%20%27Name%20of%20your%20site%27%2C-%27entree_nom_site_2%27%20=%3E%20%27Name%20of%20the%20author/%27s%20site%27%2C%20%27entree_nom_site_2%27%20=%3E%20%27Name%20of%20the%20author%C3%A2%C2%80%C2%99s%20site%27%2C%20%27entree_nouveau_passe%27%20=%3E%20%27New%20password%27%2C%20%27entree_passe_ldap%27%20=%3E%20%27Password%27%2C%20%27entree_port_annuaire%27%20=%3E%20%27Port%20number%20of%20the%20directory%27%2C%40%40%20-175%2C7%20%20175%2C7%20%40%40%20Do%20not%20submit%20this%20import%20request.%3Cp%3EFor%20more%20information%2C%20please%20see%20%3Ca%20href=?a=commitdiff_plain;h=25d4f7ecfaaf0eacbef9666c62d0152bbf27db2b;p=lhc%2Fweb%2Fwiklou.git 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' );