Merge "resourceloader: Remove outdated readyState handler for base modules request"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / objectcache / WANObjectCacheTest.php
index 0b2df61..934d49a 100644 (file)
@@ -13,6 +13,8 @@ use Wikimedia\TestingAccessWrapper;
  * @covers WANObjectCache::getProcessCache
  * @covers WANObjectCache::getNonProcessCachedKeys
  * @covers WANObjectCache::getRawKeysForWarmup
+ * @covers WANObjectCache::getInterimValue
+ * @covers WANObjectCache::setInterimValue
  */
 class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
        /** @var WANObjectCache */
@@ -157,8 +159,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( 9, $hit, "Values evicted" );
 
                $key = reset( $keys );
-               // Get into cache
+               // Get into cache (default process cache group)
                $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
+               $this->assertEquals( 10, $hit, "Value calculated" );
                $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
                $this->assertEquals( 10, $hit, "Value cached" );
                $outerCallback = function () use ( &$callback, $key ) {
@@ -166,7 +169,8 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
 
                        return 43 + $v;
                };
-               $this->cache->getWithSetCallback( $key, 100, $outerCallback );
+               // Outer key misses and refuses inner key process cache value
+               $this->cache->getWithSetCallback( "$key-miss-outer", 100, $outerCallback );
                $this->assertEquals( 11, $hit, "Nested callback value process cache skipped" );
        }
 
@@ -1318,4 +1322,27 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
 
                $this->assertSame( 'special', $wanCache->makeGlobalKey( 'a', 'b' ) );
        }
+
+       public static function statsKeyProvider() {
+               return [
+                       [ 'domain:page:5', 'page' ],
+                       [ 'domain:main-key', 'main-key' ],
+                       [ 'domain:page:history', 'page' ],
+                       [ 'missingdomainkey', 'missingdomainkey' ]
+               ];
+       }
+
+       /**
+        * @dataProvider statsKeyProvider
+        * @covers WANObjectCache::determineKeyClass
+        */
+       public function testStatsKeyClass( $key, $class ) {
+               $wanCache = TestingAccessWrapper::newFromObject( new WANObjectCache( [
+                       'cache' => new HashBagOStuff,
+                       'pool' => 'testcache-hash',
+                       'relayer' => new EventRelayerNull( [] )
+               ] ) );
+
+               $this->assertEquals( $class, $wanCache->determineKeyClass( $key ) );
+       }
 }