Merge "Remove Revision::getRevisionText from migrateArchiveText"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / objectcache / WANObjectCacheTest.php
index 329c642..7c4c9bf 100644 (file)
@@ -318,7 +318,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;
 
@@ -584,7 +584,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( 0, count( $asycList ), "No deferred refreshes added." );
                $v = $cache->getWithSetCallback( $key, 300, $func, $opts );
                $this->assertEquals( $value, $v, "New value stored" );
 
@@ -678,13 +678,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 +846,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;
 
@@ -1348,6 +1348,35 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase {
                }
        }
 
+       /**
+        * @covers WANObjectCache::get()
+        * @covers WANObjectCache::processCheckKeys()
+        */
+       public function testCheckKeyHoldoff() {
+               $cache = $this->cache;
+               $key = wfRandomString();
+               $checkKey = wfRandomString();
+
+               $mockWallClock = 1549343530.2053;
+               $cache->setMockTime( $mockWallClock );
+               $cache->touchCheckKey( $checkKey, 8 );
+
+               $mockWallClock += 1;
+               $cache->set( $key, 1, 60 );
+               $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) );
+               $this->assertLessThan( 0, $curTTL, "Key in hold-off due to check key" );
+
+               $mockWallClock += 3;
+               $cache->set( $key, 1, 60 );
+               $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) );
+               $this->assertLessThan( 0, $curTTL, "Key in hold-off due to check key" );
+
+               $mockWallClock += 10;
+               $cache->set( $key, 1, 60 );
+               $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) );
+               $this->assertGreaterThan( 0, $curTTL, "Key not in hold-off due to check key" );
+       }
+
        /**
         * @covers WANObjectCache::delete
         * @covers WANObjectCache::relayDelete
@@ -1449,7 +1478,7 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase {
                $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 );
@@ -1952,6 +1981,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' ]
                ];
        }