Krinkle has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380657 )
Change subject: objectcache: Improve WANObjectCache test coverage ...................................................................... objectcache: Improve WANObjectCache test coverage class WANObjectCache: 62% -> 65% * doGetWithSetCallback: 98% -> 100% - Add case: Throw for invalid callback. * getWithSetCallback: 86% -> 100% - Cover case: Else branch for `$cur[self::VFLD_VERSION] === $version`. * getMulti: 91% -> 98% - Cover case: If branch for `$this->warmupCache`. * set: 93% -> 100% - Cover case: If branch for `lockTSE >= 0`. * reap: 84% -> 100% - Add case: Error when changeTTL() fails. Change-Id: I4844ab0ebdd4d3ec9acc9cd4500721b04cfda317 --- M tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php 1 file changed, 41 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/57/380657/1 diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index c762aa7..fca6423 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -260,9 +260,19 @@ } /** + * @covers WANObjectCache::getWithSetCallback() + * @covers WANObjectCache::doGetWithSetCallback() + */ + public function testGetWithSetCallback_invalidCallback() { + $this->setExpectedException( InvalidArgumentException::class ); + $this->cache->getWithSetCallback( 'key', 30, 'invalid callback' ); + } + + /** * @dataProvider getMultiWithSetCallback_provider * @covers WANObjectCache::getMultiWithSetCallback() * @covers WANObjectCache::makeMultiKeys() + * @covers WANObjectCache::getMulti() * @param array $extOpts * @param bool $versioned */ @@ -618,6 +628,7 @@ /** * @covers WANObjectCache::getWithSetCallback() * @covers WANObjectCache::doGetWithSetCallback() + * @covers WANObjectCache::set() */ public function testLockTSESlow() { $cache = $this->cache; @@ -911,6 +922,8 @@ /** * @dataProvider getWithSetCallback_versions_provider + * @covers WANObjectCache::getWithSetCallback() + * @covers WANObjectCache::doGetWithSetCallback() * @param array $extOpts * @param bool $versioned */ @@ -1101,6 +1114,34 @@ } /** + * @covers WANObjectCache::reap() + */ + public function testReap_fail() { + $backend = $this->getMockBuilder( EmptyBagOStuff::class ) + ->setMethods( [ 'get', 'changeTTL' ] )->getMock(); + $backend->expects( $this->once() )->method( 'get' ) + ->willReturn( [ + WANObjectCache::FLD_VERSION => WANObjectCache::VERSION, + WANObjectCache::FLD_VALUE => 'value', + WANObjectCache::FLD_TTL => 3600, + WANObjectCache::FLD_TIME => 300, + ] ); + $backend->expects( $this->once() )->method( 'changeTTL' ) + ->willReturn( false ); + + $wanCache = new WANObjectCache( [ + 'cache' => $backend, + 'pool' => 'testcache-hash', + 'relayer' => new EventRelayerNull( [] ) + ] ); + + $isStale = null; + $ret = $wanCache->reap( 'key', 360, $isStale ); + $this->assertTrue( $isStale, 'value was stale' ); + $this->assertFalse( $ret, 'changeTTL failed' ); + } + + /** * @covers WANObjectCache::set() */ public function testSetWithLag() { -- To view, visit https://gerrit.wikimedia.org/r/380657 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4844ab0ebdd4d3ec9acc9cd4500721b04cfda317 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits