Merge "objectcache: fix WRITE_ALLOW_SEGMENTS in BagOStuff cas() and add() methods"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 20 Aug 2019 15:50:58 +0000 (15:50 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 20 Aug 2019 15:50:58 +0000 (15:50 +0000)
1  2 
tests/phpunit/includes/libs/objectcache/BagOStuffTest.php

@@@ -19,10 -19,9 +19,10 @@@ class BagOStuffTest extends MediaWikiTe
  
                // type defined through parameter
                if ( $this->getCliArg( 'use-bagostuff' ) !== null ) {
 -                      $name = $this->getCliArg( 'use-bagostuff' );
 +                      global $wgObjectCaches;
  
 -                      $this->cache = ObjectCache::newFromId( $name );
 +                      $id = $this->getCliArg( 'use-bagostuff' );
 +                      $this->cache = ObjectCache::newFromParams( $wgObjectCaches[$id] );
                } else {
                        // no type defined - use simple hash
                        $this->cache = new HashBagOStuff;
@@@ -37,7 -36,7 +37,7 @@@
         * @covers MediumSpecificBagOStuff::makeKeyInternal
         */
        public function testMakeKey() {
 -              $cache = ObjectCache::newFromId( 'hash' );
 +              $cache = new HashBagOStuff();
  
                $localKey = $cache->makeKey( 'first', 'second', 'third' );
                $globalKey = $cache->makeGlobalKey( 'first', 'second', 'third' );
                        return $oldValue . '!';
                };
  
-               foreach ( [ $tiny, $small, $big ] as $value ) {
+               $cases = [ 'tiny' => $tiny, 'small' => $small, 'big' => $big ];
+               foreach ( $cases as $case => $value ) {
                        $this->cache->set( $key, $value, 10, BagOStuff::WRITE_ALLOW_SEGMENTS );
-                       $this->assertEquals( $value, $this->cache->get( $key ) );
-                       $this->assertEquals( $value, $this->cache->getMulti( [ $key ] )[$key] );
-                       $this->assertTrue( $this->cache->merge( $key, $callback, 5 ) );
-                       $this->assertEquals( "$value!", $this->cache->get( $key ) );
-                       $this->assertEquals( "$value!", $this->cache->getMulti( [ $key ] )[$key] );
-                       $this->assertTrue( $this->cache->deleteMulti( [ $key ] ) );
-                       $this->assertFalse( $this->cache->get( $key ) );
-                       $this->assertEquals( [], $this->cache->getMulti( [ $key ] ) );
+                       $this->assertEquals( $value, $this->cache->get( $key ), "get $case" );
+                       $this->assertEquals( $value, $this->cache->getMulti( [ $key ] )[$key], "get $case" );
+                       $this->assertTrue(
+                               $this->cache->merge( $key, $callback, 5, 1, BagOStuff::WRITE_ALLOW_SEGMENTS ),
+                               "merge $case"
+                       );
+                       $this->assertEquals(
+                               "$value!",
+                               $this->cache->get( $key ),
+                               "merged $case"
+                       );
+                       $this->assertEquals(
+                               "$value!",
+                               $this->cache->getMulti( [ $key ] )[$key],
+                               "merged $case"
+                       );
+                       $this->assertTrue( $this->cache->deleteMulti( [ $key ] ), "delete $case" );
+                       $this->assertFalse( $this->cache->get( $key ), "deleted $case" );
+                       $this->assertEquals( [], $this->cache->getMulti( [ $key ] ), "deletd $case" );
  
                        $this->cache->set( $key, "@$value", 10, BagOStuff::WRITE_ALLOW_SEGMENTS );
-                       $this->assertEquals( "@$value", $this->cache->get( $key ) );
-                       $this->assertTrue( $this->cache->delete( $key, BagOStuff::WRITE_PRUNE_SEGMENTS ) );
-                       $this->assertFalse( $this->cache->get( $key ) );
-                       $this->assertEquals( [], $this->cache->getMulti( [ $key ] ) );
+                       $this->assertEquals( "@$value", $this->cache->get( $key ), "get $case" );
+                       $this->assertTrue(
+                               $this->cache->delete( $key, BagOStuff::WRITE_PRUNE_SEGMENTS ),
+                               "prune $case"
+                       );
+                       $this->assertFalse( $this->cache->get( $key ), "pruned $case" );
+                       $this->assertEquals( [], $this->cache->getMulti( [ $key ] ), "pruned $case" );
                }
  
                $this->cache->set( $key, 666, 10, BagOStuff::WRITE_ALLOW_SEGMENTS );