From 6ae5dde077bf73c654637adfc1c413b0b6b700ac Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 16 Nov 2015 16:13:37 -0800 Subject: [PATCH] objectcache: Add more WAN cache check key unit tests Change-Id: If9bfef463b294391a456c5f04f48858f9dbe73fd --- .../libs/objectcache/WANObjectCacheTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index 6495790ec8..d0ae8c990c 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -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() */ -- 2.20.1