objectcache: Add more WAN cache check key unit tests
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 17 Nov 2015 00:13:37 +0000 (16:13 -0800)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 17 Nov 2015 03:28:18 +0000 (03:28 +0000)
Change-Id: If9bfef463b294391a456c5f04f48858f9dbe73fd

tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php

index 6495790..d0ae8c9 100644 (file)
@@ -355,6 +355,37 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                $this->assertEquals( $t5, $t6, 'Check key time did not change' );
        }
 
+       /**
+        * @covers WANObjectCache::getMulti()
+        */
+       public function testGetWithSeveralCheckKeys() {
+               $key = wfRandomString();
+               $tKey1 = wfRandomString();
+               $tKey2 = wfRandomString();
+               $value = 'meow';
+
+               // Two check keys are newer (given hold-off) than $key, another is older
+               $this->internalCache->set(
+                       WANObjectCache::TIME_KEY_PREFIX . $tKey2,
+                       WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 3 )
+               );
+               $this->internalCache->set(
+                       WANObjectCache::TIME_KEY_PREFIX . $tKey2,
+                       WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 5 )
+               );
+               $this->internalCache->set(
+                       WANObjectCache::TIME_KEY_PREFIX . $tKey1,
+                       WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 30 )
+               );
+               $this->cache->set( $key, $value, 30 );
+
+               $curTTL = null;
+               $v = $this->cache->get( $key, $curTTL, array( $tKey1, $tKey2 ) );
+               $this->assertEquals( $value, $v, "Value matches" );
+               $this->assertLessThan( -5, $curTTL, "Correct CTL" );
+               $this->assertGreaterThan( -5.1, $curTTL, "Correct CTL" );
+       }
+
        /**
         * @covers WANObjectCache::set()
         */