jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/345959 )
Change subject: objectcache: Never use CACHE_NONE for CACHE_ANYTHING ...................................................................... objectcache: Never use CACHE_NONE for CACHE_ANYTHING If $wgMainCacheType = CACHE_ACCEL, but there is no APC, then its possible that CACHE_ANYTHING will default to CACHE_NONE because that's what CACHE_ACCEL would do. Possibly also T147161 Bug: T160519 Change-Id: I9ac2d071437b35a0f9cd3678e2279628f7b1931e (cherry picked from commit c5a0fa5bed4c5aafdf0721c1d05978576107bd85) --- M RELEASE-NOTES-1.28 M includes/objectcache/ObjectCache.php A tests/phpunit/includes/objectcache/ObjectCacheTest.php 3 files changed, 90 insertions(+), 1 deletion(-) Approvals: Brian Wolff: Looks good to me, approved jenkins-bot: Verified diff --git a/RELEASE-NOTES-1.28 b/RELEASE-NOTES-1.28 index 327a624..265c5b2 100644 --- a/RELEASE-NOTES-1.28 +++ b/RELEASE-NOTES-1.28 @@ -14,6 +14,7 @@ * (T158766) Avoid SQL error on MSSQL when using selectRowCount() * (T145635) Fix too long index error when installing with MSSQL * (T156184) $wgRawHtml will no longer apply to internationalization messages. +* (T160519) CACHE_ANYTHING will not be CACHE_ACCEL if no accelerator is installed. == MediaWiki 1.28 == diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 0a4f0ed..a253c36 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -246,8 +246,14 @@ global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType; $candidates = [ $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType ]; foreach ( $candidates as $candidate ) { + $cache = false; if ( $candidate !== CACHE_NONE && $candidate !== CACHE_ANYTHING ) { - return self::getInstance( $candidate ); + $cache = self::getInstance( $candidate ); + // CACHE_ACCEL might default to nothing if no APCu + // See includes/ServiceWiring.php + if ( !( $cache instanceof EmptyBagOStuff ) ) { + return $cache; + } } } diff --git a/tests/phpunit/includes/objectcache/ObjectCacheTest.php b/tests/phpunit/includes/objectcache/ObjectCacheTest.php new file mode 100644 index 0000000..d132183 --- /dev/null +++ b/tests/phpunit/includes/objectcache/ObjectCacheTest.php @@ -0,0 +1,82 @@ +<?php + +class ObjectCacheTest extends MediaWikiTestCase { + + protected function setUp() { + // Parent calls ObjectCache::clear() among other things + parent::setUp(); + + $this->setCacheConfig(); + $this->setMwGlobals( [ + 'wgMainCacheType' => CACHE_NONE, + 'wgMessageCacheType' => CACHE_NONE, + 'wgParserCacheType' => CACHE_NONE, + ] ); + } + + private function setCacheConfig( $arr = [] ) { + $defaults = [ + CACHE_NONE => [ 'class' => 'EmptyBagOStuff' ], + CACHE_DB => [ 'class' => 'SqlBagOStuff' ], + CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ], + // Mock ACCEL with 'hash' as being installed. + // This makes tests deterministic regardless of APC. + CACHE_ACCEL => [ 'class' => 'HashBagOStuff' ], + 'hash' => [ 'class' => 'HashBagOStuff' ], + ]; + $this->setMwGlobals( 'wgObjectCaches', $arr + $defaults ); + } + + /** @covers ObjectCache::newAnything */ + public function testNewAnythingNothing() { + $this->assertInstanceOf( + SqlBagOStuff::class, + ObjectCache::newAnything( [] ), + 'No available types. Fallback to DB' + ); + } + + /** @covers ObjectCache::newAnything */ + public function testNewAnythingHash() { + $this->setMwGlobals( [ + 'wgMainCacheType' => 'hash' + ] ); + + $this->assertInstanceOf( + HashBagOStuff::class, + ObjectCache::newAnything( [] ), + 'Use an available type (hash)' + ); + } + + /** @covers ObjectCache::newAnything */ + public function testNewAnythingAccel() { + $this->setMwGlobals( [ + 'wgMainCacheType' => CACHE_ACCEL + ] ); + + $this->assertInstanceOf( + HashBagOStuff::class, + ObjectCache::newAnything( [] ), + 'Use an available type (CACHE_ACCEL)' + ); + } + + /** @covers ObjectCache::newAnything */ + public function txestNewAnythingNoAccel() { + $this->setMwGlobals( [ + 'wgMainCacheType' => CACHE_ACCEL + ] ); + + $this->setCacheConfig( [ + // Mock APC not being installed (T160519, T147161) + CACHE_ACCEL => [ 'class' => 'EmptyBagOStuff' ] + ] ); + + $this->assertInstanceOf( + SqlBagOStuff::class, + ObjectCache::newAnything( [] ), + 'Fallback to DB if available types fall back to Empty' + ); + } +} -- To view, visit https://gerrit.wikimedia.org/r/345959 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9ac2d071437b35a0f9cd3678e2279628f7b1931e Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/core Gerrit-Branch: REL1_28 Gerrit-Owner: Martineznovo <martinezn...@gmail.com> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com> Gerrit-Reviewer: Chad <ch...@wikimedia.org> Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Martineznovo <martinezn...@gmail.com> Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits