FileBackendIntegrationTest was running tests against different backends in an unconventional way, using a combination of wrapper test cases that run tests against two different classes, and CLI options which don't really exist anymore and have an associated fixme. So: * Move the bulk of FileBackendIntegrationTest to a new abstract base class under tests/phpunit/integration. * Add subclasses for the FS and multiwrite test cases. This allows us to eliminate the wrappers. * Add a subclass for MemoryFileBackend. * Add a Swift subclass which replaces the main use case for the CLI option --use-filebackend. It is automatically enabled when a Swift backend is configured, similar to PostgreSQL tests. * Some miscellaneous tests with a medium level of integration, not requiring backend setup and teardown, were moved to new classes FileBackendMultiWriteTest and FileBackendStoreTest. Change-Id: I0da531349d7627970a7bcb34f3c1f5fd7e05cb21
108 lines
2.8 KiB
PHP
108 lines
2.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Deferred\DeferredUpdates;
|
|
use MediaWiki\WikiMap\WikiMap;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* @group FileRepo
|
|
* @group FileBackend
|
|
* @covers FileBackendMultiWrite
|
|
*/
|
|
class FileBackendMultiWriteTest extends MediaWikiIntegrationTestCase {
|
|
public function testReadAffinity() {
|
|
$be = TestingAccessWrapper::newFromObject(
|
|
new FileBackendMultiWrite( [
|
|
'name' => 'localtesting',
|
|
'wikiId' => WikiMap::getCurrentWikiId() . mt_rand(),
|
|
'backends' => [
|
|
[ // backend 0
|
|
'name' => 'multitesting0',
|
|
'class' => MemoryFileBackend::class,
|
|
'isMultiMaster' => false,
|
|
'readAffinity' => true
|
|
],
|
|
[ // backend 1
|
|
'name' => 'multitesting1',
|
|
'class' => MemoryFileBackend::class,
|
|
'isMultiMaster' => true
|
|
]
|
|
]
|
|
] )
|
|
);
|
|
|
|
$this->assertSame(
|
|
1,
|
|
$be->getReadIndexFromParams( [ 'latest' => 1 ] ),
|
|
'Reads with "latest" flag use backend 1'
|
|
);
|
|
$this->assertSame(
|
|
0,
|
|
$be->getReadIndexFromParams( [ 'latest' => 0 ] ),
|
|
'Reads without "latest" flag use backend 0'
|
|
);
|
|
|
|
$p = 'container/test-cont/file.txt';
|
|
$be->backends[0]->quickCreate( [
|
|
'dst' => "mwstore://multitesting0/$p", 'content' => 'cattitude' ] );
|
|
$be->backends[1]->quickCreate( [
|
|
'dst' => "mwstore://multitesting1/$p", 'content' => 'princess of power' ] );
|
|
|
|
$this->assertEquals(
|
|
'cattitude',
|
|
$be->getFileContents( [ 'src' => "mwstore://localtesting/$p" ] ),
|
|
"Non-latest read came from backend 0"
|
|
);
|
|
$this->assertEquals(
|
|
'princess of power',
|
|
$be->getFileContents( [ 'src' => "mwstore://localtesting/$p", 'latest' => 1 ] ),
|
|
"Latest read came from backend1"
|
|
);
|
|
}
|
|
|
|
public function testAsyncWrites() {
|
|
$be = TestingAccessWrapper::newFromObject(
|
|
new FileBackendMultiWrite( [
|
|
'name' => 'localtesting',
|
|
'wikiId' => WikiMap::getCurrentWikiId() . mt_rand(),
|
|
'backends' => [
|
|
[ // backend 0
|
|
'name' => 'multitesting0',
|
|
'class' => MemoryFileBackend::class,
|
|
'isMultiMaster' => false
|
|
],
|
|
[ // backend 1
|
|
'name' => 'multitesting1',
|
|
'class' => MemoryFileBackend::class,
|
|
'isMultiMaster' => true
|
|
]
|
|
],
|
|
'replication' => 'async'
|
|
] )
|
|
);
|
|
|
|
$cleanup = DeferredUpdates::preventOpportunisticUpdates();
|
|
|
|
$p = 'container/test-cont/file.txt';
|
|
$be->quickCreate( [
|
|
'dst' => "mwstore://localtesting/$p", 'content' => 'cattitude' ] );
|
|
|
|
$this->assertFalse(
|
|
$be->backends[0]->getFileContents( [ 'src' => "mwstore://multitesting0/$p" ] ),
|
|
"File not yet written to backend 0"
|
|
);
|
|
$this->assertEquals(
|
|
'cattitude',
|
|
$be->backends[1]->getFileContents( [ 'src' => "mwstore://multitesting1/$p" ] ),
|
|
"File already written to backend 1"
|
|
);
|
|
|
|
DeferredUpdates::doUpdates();
|
|
|
|
$this->assertEquals(
|
|
'cattitude',
|
|
$be->backends[0]->getFileContents( [ 'src' => "mwstore://multitesting0/$p" ] ),
|
|
"File now written to backend 0"
|
|
);
|
|
}
|
|
}
|