X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fphpunit%2Fincludes%2Flibs%2Fobjectcache%2FWANObjectCacheTest.php;h=5586fa1bec20b6a4c89afaca124c5dc516f01685;hb=cff596804a6582bf637b4bc28abc8d75d1e4d7f9;hp=ac988e6467ab557314195fbce74ab99d89e1ef53;hpb=eb4ac89d6690ed4504206de5678a9a50e5edaadf;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index ac988e6467..5586fa1bec 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -128,6 +128,32 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { $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 */ @@ -318,7 +344,7 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { $v = $cache->getWithSetCallback( $key, 30, $func, [ 'lowTTL' => 0, 'lockTSE' => 5 ] + $extOpts ); $this->assertEquals( $value, $v, "Value returned" ); - $this->assertEquals( 0, $wasSet, "Value not regenerated" ); + $this->assertSame( 0, $wasSet, "Value not regenerated" ); $mockWallClock += 1; @@ -381,8 +407,8 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { $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( @@ -397,8 +423,8 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { $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; @@ -414,8 +440,8 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { ); $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( @@ -584,7 +610,7 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { $asycList[0](); // run the refresh callback $asycList = []; $this->assertEquals( 2, $wasSet, "Value calculated at later time" ); - $this->assertEquals( 0, count( $asycList ), "No deferred refreshes added." ); + $this->assertSame( [], $asycList, "No deferred refreshes added." ); $v = $cache->getWithSetCallback( $key, 300, $func, $opts ); $this->assertEquals( $value, $v, "New value stored" ); @@ -678,13 +704,13 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { $keyedIds, 30, $genFunc, [ 'lowTTL' => 0, 'lockTSE' => 5 ] + $extOpts ); $this->assertEquals( $value, $v[$keyB], "Value returned" ); $this->assertEquals( 1, $wasSet, "Value regenerated" ); - $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" ); + $this->assertSame( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" ); $v = $cache->getMultiWithSetCallback( $keyedIds, 30, $genFunc, [ 'lowTTL' => 0, 'lockTSE' => 5 ] + $extOpts ); $this->assertEquals( $value, $v[$keyB], "Value returned" ); $this->assertEquals( 1, $wasSet, "Value not regenerated" ); - $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" ); + $this->assertSame( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" ); $mockWallClock += 1; @@ -846,13 +872,13 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { $keyedIds, 30, $genFunc, [ 'lowTTL' => 0 ] + $extOpts ); $this->assertEquals( $value, $v[$keyB], "Value returned" ); $this->assertEquals( 1, $wasSet, "Value regenerated" ); - $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" ); + $this->assertSame( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" ); $v = $cache->getMultiWithUnionSetCallback( $keyedIds, 30, $genFunc, [ 'lowTTL' => 0 ] + $extOpts ); $this->assertEquals( $value, $v[$keyB], "Value returned" ); $this->assertEquals( 1, $wasSet, "Value not regenerated" ); - $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" ); + $this->assertSame( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" ); $mockWallClock += 1; @@ -1473,12 +1499,12 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { $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 ); $this->assertEquals( $valueV2, $v, "Value not regenerated (secondary key)" ); - $this->assertEquals( 0, $wasSet, "Value not regenerated (secondary key)" ); + $this->assertSame( 0, $wasSet, "Value not regenerated (secondary key)" ); // Clear out the older or unversioned key $cache->delete( $key, 0 ); @@ -1981,6 +2007,8 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { [ 'domain:page:5', 'page' ], [ 'domain:main-key', 'main-key' ], [ 'domain:page:history', 'page' ], + // Regression test for T232907 + [ 'domain:foo-bar-1.2:abc:v2', 'foo-bar-1_2' ], [ 'missingdomainkey', 'missingdomainkey' ] ]; }