Fix WAN cache stashing bug due to missing list() call
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 15 Jun 2016 16:40:34 +0000 (09:40 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 15 Jun 2016 16:40:34 +0000 (09:40 -0700)
Fixes regression from 0a38dbc809.

Bug: T137877
Change-Id: I4ea960966c084ada36dc54d4ec8729126c17ccdc

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

index 45713cc..ab702d5 100644 (file)
@@ -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];
 
index 3a4aab4..5bc1c8d 100644 (file)
@@ -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' );
        }
 
        /**