From fd4940a1b6120142d353f3e4e4062c5df1518a15 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 15 Jun 2016 09:40:34 -0700 Subject: [PATCH] Fix WAN cache stashing bug due to missing list() call Fixes regression from 0a38dbc809. Bug: T137877 Change-Id: I4ea960966c084ada36dc54d4ec8729126c17ccdc --- includes/libs/objectcache/WANObjectCache.php | 2 +- .../libs/objectcache/WANObjectCacheTest.php | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 45713cc814..ab702d57be 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -902,7 +902,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { // For hot keys, either another thread has the lock or the lock failed; // use the INTERIM value from the last thread that regenerated it. $wrapped = $this->cache->get( self::INTERIM_KEY_PREFIX . $key ); - $value = $this->unwrap( $wrapped, microtime( true ) ); + list( $value ) = $this->unwrap( $wrapped, microtime( true ) ); if ( $value !== false && $this->isValid( $value, $versioned, $asOf, $minTime ) ) { $asOf = $wrapped[self::FLD_TIME]; diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index 3a4aab487f..5bc1c8dbea 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -217,9 +217,23 @@ class WANObjectCacheTest extends MediaWikiTestCase { // Acquire a lock to verify that getWithSetCallback uses lockTSE properly $this->internalCache->lock( $key, 0 ); - $ret = $cache->getWithSetCallback( $key, 30, $func, [ 'lockTSE' => 5 ] ); + + $checkKeys = [ wfRandomString() ]; // new check keys => force misses + $ret = $cache->getWithSetCallback( $key, 30, $func, + [ 'lockTSE' => 5, 'checkKeys' => $checkKeys ] ); $this->assertEquals( $value, $ret ); $this->assertEquals( 1, $calls, 'Callback was not used' ); + + $cache->delete( $key ); + $ret = $cache->getWithSetCallback( $key, 30, $func, + [ 'lockTSE' => 5, 'checkKeys' => $checkKeys ] ); // should use interim value + $this->assertEquals( $value, $ret ); + $this->assertEquals( 2, $calls, 'Callback was used' ); + + $ret = $cache->getWithSetCallback( $key, 30, $func, + [ 'lockTSE' => 5, 'checkKeys' => $checkKeys ] ); + $this->assertEquals( $value, $ret ); + $this->assertEquals( 2, $calls, 'Callback was not used; used interim' ); } /** -- 2.20.1