From: jenkins-bot Date: Fri, 27 Sep 2019 22:43:09 +0000 (+0000) Subject: Merge "tests: Replace PHPUnit's loose assertEquals(null) with assertNull()" X-Git-Tag: 1.34.0-rc.0~63 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=864c4df8b9cf46ebe1cc32193230b93333553b1e;hp=-c Merge "tests: Replace PHPUnit's loose assertEquals(null) with assertNull()" --- 864c4df8b9cf46ebe1cc32193230b93333553b1e diff --combined tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index 72ac5675b8,61d3785bc0..0c084e058a --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@@ -128,32 -128,6 +128,32 @@@ class WANObjectCacheTest extends PHPUni $this->assertFalse( $this->cache->get( $key ), "Stale set() value ignored" ); } + /** + * @covers WANObjectCache::getWithSetCallback + */ + public function testProcessCacheTTL() { + $cache = $this->cache; + $mockWallClock = 1549343530.2053; + $cache->setMockTime( $mockWallClock ); + + $key = "mykey-" . wfRandomString(); + + $hits = 0; + $callback = function ( $oldValue, &$ttl, &$setOpts ) use ( &$hits ) { + ++$hits; + return 42; + }; + + $cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] ); + $cache->delete( $key, $cache::HOLDOFF_NONE ); // clear persistent cache + $cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] ); + $this->assertEquals( 1, $hits, "Value process cached" ); + + $mockWallClock += 6; + $cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] ); + $this->assertEquals( 2, $hits, "Value expired in process cache" ); + } + /** * @covers WANObjectCache::getWithSetCallback */ @@@ -407,8 -381,8 +407,8 @@@ $v = $cache->getWithSetCallback( $key, 30, $checkFunc, [ 'staleTTL' => 50 ] + $extOpts ); $this->assertEquals( 'xxx1', $v, "Value returned" ); - $this->assertEquals( false, $oldValReceived, "Callback got no stale value" ); - $this->assertEquals( null, $oldAsOfReceived, "Callback got no stale value" ); + $this->assertFalse( $oldValReceived, "Callback got no stale value" ); + $this->assertNull( $oldAsOfReceived, "Callback got no stale value" ); $mockWallClock += 40; $v = $cache->getWithSetCallback( @@@ -423,8 -397,8 +423,8 @@@ $key, 30, $checkFunc, [ 'staleTTL' => 50 ] + $extOpts ); $this->assertEquals( 'xxx3', $v, "Value still returned after expired" ); $this->assertEquals( 3, $wasSet, "Value recalculated while expired" ); - $this->assertEquals( false, $oldValReceived, "Callback got no stale value" ); - $this->assertEquals( null, $oldAsOfReceived, "Callback got no stale value" ); + $this->assertFalse( $oldValReceived, "Callback got no stale value" ); + $this->assertNull( $oldAsOfReceived, "Callback got no stale value" ); $mockWallClock = ( $priorTime - $cache::HOLDOFF_TTL - 1 ); $wasSet = 0; @@@ -440,8 -414,8 +440,8 @@@ ); $this->assertEquals( 'xxx1', $v, "Value returned" ); $this->assertEquals( 1, $wasSet, "Value computed" ); - $this->assertEquals( false, $oldValReceived, "Callback got no stale value" ); - $this->assertEquals( null, $oldAsOfReceived, "Callback got no stale value" ); + $this->assertFalse( $oldValReceived, "Callback got no stale value" ); + $this->assertNull( $oldAsOfReceived, "Callback got no stale value" ); $mockWallClock += $cache::TTL_HOUR; // some time passes $v = $cache->getWithSetCallback( @@@ -1499,7 -1473,7 +1499,7 @@@ $this->assertEquals( $valueV2, $v, "Value returned" ); $this->assertEquals( 1, $wasSet, "Value regenerated" ); $this->assertEquals( false, $priorValue, "Old value not given due to old format" ); - $this->assertEquals( null, $priorAsOf, "Old value not given due to old format" ); + $this->assertNull( $priorAsOf, "Old value not given due to old format" ); $wasSet = 0; $v = $cache->getWithSetCallback( $key, 30, $funcV2, $verOpts + $extOpts );