Added testStaleSet() WAN cache test
[lhc/web/wiklou.git] / tests / phpunit / includes / objectcache / WANObjectCacheTest.php
index 47a83b3..742b737 100644 (file)
@@ -74,6 +74,14 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                }
        }
 
+       public function testStaleSet() {
+               $key = wfRandomString();
+               $value = wfRandomString();
+               $this->cache->set( $key, $value, 3, array( 'since' => microtime( true ) - 30 ) );
+
+               $this->assertFalse( $this->cache->get( $key ), "Stale set() value ignored" );
+       }
+
        /**
         * @covers WANObjectCache::getWithSetCallback()
         */
@@ -224,13 +232,16 @@ class WANObjectCacheTest extends MediaWikiTestCase {
 
        /**
         * @covers WANObjectCache::touchCheckKey()
+        * @covers WANObjectCache::resetCheckKey()
         * @covers WANObjectCache::getCheckKeyTime()
         */
        public function testTouchKeys() {
                $key = wfRandomString();
 
+               $priorTime = microtime( true );
+               usleep( 1 );
                $t0 = $this->cache->getCheckKeyTime( $key );
-               $this->assertFalse( $t0, 'Check key time is false' );
+               $this->assertGreaterThanOrEqual( $priorTime, $t0, 'Check key auto-created' );
 
                $priorTime = microtime( true );
                usleep( 1 );
@@ -248,5 +259,13 @@ class WANObjectCacheTest extends MediaWikiTestCase {
 
                $t4 = $this->cache->getCheckKeyTime( $key );
                $this->assertEquals( $t3, $t4, 'Check key time did not change' );
+
+               usleep( 1 );
+               $this->cache->resetCheckKey( $key );
+               $t5 = $this->cache->getCheckKeyTime( $key );
+               $this->assertGreaterThan( $t4, $t5, 'Check key time increased' );
+
+               $t6 = $this->cache->getCheckKeyTime( $key );
+               $this->assertEquals( $t5, $t6, 'Check key time did not change' );
        }
 }