summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/objectcache/BagOStuffTest.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-20 09:00:55 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-20 09:00:55 +0100
commita2190ac74dd4d7080b12bab90e552d7aa81209ef (patch)
tree8b31f38de9882d18df54cf8d9e0de74167a094eb /tests/phpunit/includes/objectcache/BagOStuffTest.php
parent15e69f7b20b6596b9148030acce5b59993b95a45 (diff)
parent257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff)
Merge branch 'mw-1.26'
Diffstat (limited to 'tests/phpunit/includes/objectcache/BagOStuffTest.php')
-rw-r--r--tests/phpunit/includes/objectcache/BagOStuffTest.php34
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/phpunit/includes/objectcache/BagOStuffTest.php b/tests/phpunit/includes/objectcache/BagOStuffTest.php
index 4516bb4e..b6840062 100644
--- a/tests/phpunit/includes/objectcache/BagOStuffTest.php
+++ b/tests/phpunit/includes/objectcache/BagOStuffTest.php
@@ -1,8 +1,10 @@
<?php
/**
* @author Matthias Mullie <mmullie@wikimedia.org>
+ * @group BagOStuff
*/
class BagOStuffTest extends MediaWikiTestCase {
+ /** @var BagOStuff */
private $cache;
protected function setUp() {
@@ -136,20 +138,48 @@ class BagOStuffTest extends MediaWikiTestCase {
public function testGetMulti() {
$value1 = array( 'this' => 'is', 'a' => 'test' );
$value2 = array( 'this' => 'is', 'another' => 'test' );
+ $value3 = array( 'testing a key that may be encoded when sent to cache backend' );
$key1 = wfMemcKey( 'test1' );
$key2 = wfMemcKey( 'test2' );
+ $key3 = wfMemcKey( 'will-%-encode' ); // internally, MemcachedBagOStuffs will encode to will-%25-encode
$this->cache->add( $key1, $value1 );
$this->cache->add( $key2, $value2 );
+ $this->cache->add( $key3, $value3 );
$this->assertEquals(
- $this->cache->getMulti( array( $key1, $key2 ) ),
- array( $key1 => $value1, $key2 => $value2 )
+ array( $key1 => $value1, $key2 => $value2, $key3 => $value3 ),
+ $this->cache->getMulti( array( $key1, $key2, $key3 ) )
);
// cleanup
$this->cache->delete( $key1 );
$this->cache->delete( $key2 );
+ $this->cache->delete( $key3 );
+ }
+
+ /**
+ * @covers BagOStuff::getScopedLock
+ */
+ public function testGetScopedLock() {
+ $key = wfMemcKey( 'test' );
+ $value1 = $this->cache->getScopedLock( $key, 0 );
+ $value2 = $this->cache->getScopedLock( $key, 0 );
+
+ $this->assertType( 'ScopedCallback', $value1, 'First call returned lock' );
+ $this->assertNull( $value2, 'Duplicate call returned no lock' );
+
+ unset( $value1 );
+
+ $value3 = $this->cache->getScopedLock( $key, 0 );
+ $this->assertType( 'ScopedCallback', $value3, 'Lock returned callback after release' );
+ unset( $value3 );
+
+ $value1 = $this->cache->getScopedLock( $key, 0, 5, 'reentry' );
+ $value2 = $this->cache->getScopedLock( $key, 0, 5, 'reentry' );
+
+ $this->assertType( 'ScopedCallback', $value1, 'First reentrant call returned lock' );
+ $this->assertType( 'ScopedCallback', $value1, 'Second reentrant call returned lock' );
}
}