wiki.techinc.nl/tests/phpunit/integration/includes/filerepo/LocalAndForeignDBRepoTest.php
Aaron Schulz 57b2e2d6ac filerepo: remove repo name from getSharedCacheKey()
The name is only used for local config and internal virtual URLs.
A key use case is having a LocalRepo named "local" on central repo
wiki and a ForeignDBViaLBRepo named "shared" on the client wikis,
the later being a reference to the former. The keys should be be
shared regardless of this naming difference.

Bug: T267668
Change-Id: Ic239bb980740ec5237edc878af4274885034a96f
2020-11-16 17:28:31 -08:00

87 lines
2.5 KiB
PHP

<?php
class LocalAndForeignDBRepoTest extends MediaWikiIntegrationTestCase {
/**
* @covers LocalRepo::getSharedCacheKey
* @covers ForeignDBViaLBRepo::getSharedCacheKey
*/
public function testsSharedCacheKey() {
$wikiId = WikiMap::getCurrentWikiDbDomain()->getId();
$wanCache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
$localRepo = new LocalRepo( [
'name' => 'local',
'backend' => 'local-backend',
'wanCache' => $wanCache
] );
$foreignRepo = new ForeignDBViaLBRepo( [
'name' => 'local',
'backend' => 'local-backend',
'wiki' => $wikiId,
'hasSharedCache' => true,
'wanCache' => $wanCache
] );
$foreignRepo2 = new ForeignDBViaLBRepo( [
'name' => 'local',
'backend' => 'local-backend',
'wiki' => 'weirdoutside-domain',
'hasSharedCache' => true,
'wanCache' => $wanCache
] );
$sharedKeyForLocal = $localRepo->getSharedCacheKey( 'class', 93 );
$sharedKeyForForeign = $foreignRepo->getSharedCacheKey( 'class', 93 );
$sharedKeyForForiegn2 = $foreignRepo2->getSharedCacheKey( 'class', 93 );
$this->assertSame(
$wanCache->makeGlobalKey( 'filerepo-class', $wikiId, 93 ),
$sharedKeyForLocal,
"Shared key (repo is on local domain)"
);
$this->assertSame(
$sharedKeyForLocal,
$sharedKeyForForeign,
"Shared key (repo is on foreign domain)"
);
$this->assertSame(
$wanCache->makeGlobalKey( 'filerepo-class', 'weirdoutside-domain', 93 ),
$sharedKeyForForiegn2,
"Shared key (repo is on a different foreign domain)"
);
}
/**
* @covers LocalRepo::getLocalCacheKey
* @covers ForeignDBViaLBRepo::getLocalCacheKey
*/
public function testsLocalCacheKey() {
$wikiId = WikiMap::getCurrentWikiDbDomain()->getId();
$wanCache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
$localRepo = new LocalRepo( [
'name' => 'local',
'backend' => 'local-backend',
'wanCache' => $wanCache
] );
$foreignRepo = new ForeignDBViaLBRepo( [
'name' => 'local',
'backend' => 'local-backend',
'wiki' => $wikiId,
'hasSharedCache' => true,
'wanCache' => $wanCache
] );
$nonsharedKeyForLocal = $localRepo->getLocalCacheKey( 'class', 93 );
$nonsharedKeyForForeign = $foreignRepo->getLocalCacheKey( 'class', 93 );
$this->assertSame(
$wanCache->makeKey( 'filerepo-class', 'local', 93 ),
$nonsharedKeyForLocal,
"Non-shared key (repo is on local domain)"
);
$this->assertSame(
$wanCache->makeKey( 'filerepo-class', 'local', 93 ),
$nonsharedKeyForForeign,
"Non-shared key (repo is on local domain)"
);
}
}