* @covers WANObjectCache::getWithSetCallback()
* @covers WANObjectCache::fetchOrRegenerate()
*/
- public function testBusyValue() {
+ public function testBusyValueBasic() {
$cache = $this->cache;
$key = wfRandomString();
$value = wfRandomString();
$cache->setMockTime( $mockWallClock );
$calls = 0;
- $func = function () use ( &$calls, $value, $cache, $key ) {
+ $func = function () use ( &$calls, $value ) {
++$calls;
return $value;
};
$this->assertEquals( 3, $calls, 'Callback was not used; used interim' );
}
+ public function getBusyValues_Provider() {
+ $hash = new HashBagOStuff( [] );
+
+ return [
+ [
+ function () {
+ return "Saint Oliver Plunckett";
+ },
+ 'Saint Oliver Plunckett'
+ ],
+ [ 'strlen', 'strlen' ],
+ [ 'WANObjectCache::newEmpty', 'WANObjectCache::newEmpty' ],
+ [ [ 'WANObjectCache', 'newEmpty' ], [ 'WANObjectCache', 'newEmpty' ] ],
+ [ [ $hash, 'getLastError' ], [ $hash, 'getLastError' ] ],
+ [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]
+ ];
+ }
+
+ /**
+ * @covers WANObjectCache::getWithSetCallback()
+ * @covers WANObjectCache::fetchOrRegenerate()
+ * @dataProvider getBusyValues_Provider
+ * @param mixed $busyValue
+ * @param mixed $expected
+ */
+ public function testBusyValueTypes( $busyValue, $expected ) {
+ $cache = $this->cache;
+ $key = wfRandomString();
+
+ $mockWallClock = 1549343530.2053;
+ $cache->setMockTime( $mockWallClock );
+
+ $calls = 0;
+ $func = function () use ( &$calls ) {
+ ++$calls;
+ return 418;
+ };
+
+ // Acquire a lock to verify that getWithSetCallback uses busyValue properly
+ $this->internalCache->add( 'WANCache:m:' . $key, 1, 0 );
+
+ $ret = $cache->getWithSetCallback( $key, 30, $func, [ 'busyValue' => $busyValue ] );
+ $this->assertSame( $expected, $ret, 'busyValue used as expected' );
+ $this->assertSame( 0, $calls, 'busyValue was used' );
+ }
+
/**
* @covers WANObjectCache::getMulti()
*/
}
}
+ /**
+ * @covers WANObjectCache::get()
+ * @covers WANObjectCache::processCheckKeys()
+ */
+ public function testCheckKeyHoldoff() {
+ $cache = $this->cache;
+ $key = wfRandomString();
+ $checkKey = wfRandomString();
+
+ $mockWallClock = 1549343530.2053;
+ $cache->setMockTime( $mockWallClock );
+ $cache->touchCheckKey( $checkKey, 8 );
+
+ $mockWallClock += 1;
+ $cache->set( $key, 1, 60 );
+ $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) );
+ $this->assertLessThan( 0, $curTTL, "Key in hold-off due to check key" );
+
+ $mockWallClock += 3;
+ $cache->set( $key, 1, 60 );
+ $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) );
+ $this->assertLessThan( 0, $curTTL, "Key in hold-off due to check key" );
+
+ $mockWallClock += 10;
+ $cache->set( $key, 1, 60 );
+ $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) );
+ $this->assertGreaterThan( 0, $curTTL, "Key not in hold-off due to check key" );
+ }
+
/**
* @covers WANObjectCache::delete
* @covers WANObjectCache::relayDelete
* @covers WANObjectCache::makeKey
*/
public function testMakeKey() {
+ if ( defined( 'HHVM_VERSION' ) ) {
+ $this->markTestSkipped( 'HHVM Reflection buggy' );
+ }
+
$backend = $this->getMockBuilder( HashBagOStuff::class )
->setMethods( [ 'makeKey' ] )->getMock();
$backend->expects( $this->once() )->method( 'makeKey' )
* @covers WANObjectCache::makeGlobalKey
*/
public function testMakeGlobalKey() {
+ if ( defined( 'HHVM_VERSION' ) ) {
+ $this->markTestSkipped( 'HHVM Reflection buggy' );
+ }
+
$backend = $this->getMockBuilder( HashBagOStuff::class )
->setMethods( [ 'makeGlobalKey' ] )->getMock();
$backend->expects( $this->once() )->method( 'makeGlobalKey' )
[ 'domain:page:5', 'page' ],
[ 'domain:main-key', 'main-key' ],
[ 'domain:page:history', 'page' ],
+ // Regression test for T232907
+ [ 'domain:foo-bar-1.2:abc:v2', 'foo-bar-1_2' ],
[ 'missingdomainkey', 'missingdomainkey' ]
];
}