2018-01-16 13:53:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Tests\Storage;
|
|
|
|
|
|
|
|
|
|
use BagOStuff;
|
|
|
|
|
use EmptyBagOStuff;
|
|
|
|
|
use HashBagOStuff;
|
|
|
|
|
use MediaWiki\Storage\NameTableAccessException;
|
|
|
|
|
use MediaWiki\Storage\NameTableStore;
|
|
|
|
|
use MediaWikiTestCase;
|
|
|
|
|
use Psr\Log\NullLogger;
|
|
|
|
|
use WANObjectCache;
|
|
|
|
|
use Wikimedia\Rdbms\Database;
|
|
|
|
|
use Wikimedia\Rdbms\LoadBalancer;
|
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Addshore
|
|
|
|
|
* @group Database
|
|
|
|
|
* @covers \MediaWiki\Storage\NameTableStore
|
|
|
|
|
*/
|
|
|
|
|
class NameTableStoreTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
|
$this->tablesUsed[] = 'slot_roles';
|
|
|
|
|
parent::setUp();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-22 16:02:49 +00:00
|
|
|
protected function addCoreDBData() {
|
|
|
|
|
// The default implementation causes the slot_roles to already have content. Skip that.
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 13:53:22 +00:00
|
|
|
private function populateTable( $values ) {
|
|
|
|
|
$insertValues = [];
|
|
|
|
|
foreach ( $values as $name ) {
|
|
|
|
|
$insertValues[] = [ 'role_name' => $name ];
|
|
|
|
|
}
|
|
|
|
|
$this->db->insert( 'slot_roles', $insertValues );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getHashWANObjectCache( $cacheBag ) {
|
|
|
|
|
return new WANObjectCache( [ 'cache' => $cacheBag ] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $db
|
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|LoadBalancer
|
|
|
|
|
*/
|
|
|
|
|
private function getMockLoadBalancer( $db ) {
|
|
|
|
|
$mock = $this->getMockBuilder( LoadBalancer::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$mock->expects( $this->any() )
|
|
|
|
|
->method( 'getConnection' )
|
|
|
|
|
->willReturn( $db );
|
|
|
|
|
return $mock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getCallCheckingDb( $insertCalls, $selectCalls ) {
|
|
|
|
|
$mock = $this->getMockBuilder( Database::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$mock->expects( $this->exactly( $insertCalls ) )
|
|
|
|
|
->method( 'insert' )
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
->willReturnCallback( function ( ...$args ) {
|
|
|
|
|
return call_user_func_array( [ $this->db, 'insert' ], $args );
|
2018-01-16 13:53:22 +00:00
|
|
|
} );
|
|
|
|
|
$mock->expects( $this->exactly( $selectCalls ) )
|
|
|
|
|
->method( 'select' )
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
->willReturnCallback( function ( ...$args ) {
|
|
|
|
|
return call_user_func_array( [ $this->db, 'select' ], $args );
|
2018-01-16 13:53:22 +00:00
|
|
|
} );
|
|
|
|
|
$mock->expects( $this->exactly( $insertCalls ) )
|
|
|
|
|
->method( 'affectedRows' )
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
->willReturnCallback( function ( ...$args ) {
|
|
|
|
|
return call_user_func_array( [ $this->db, 'affectedRows' ], $args );
|
2018-01-16 13:53:22 +00:00
|
|
|
} );
|
|
|
|
|
$mock->expects( $this->any() )
|
|
|
|
|
->method( 'insertId' )
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
->willReturnCallback( function ( ...$args ) {
|
|
|
|
|
return call_user_func_array( [ $this->db, 'insertId' ], $args );
|
2018-01-16 13:53:22 +00:00
|
|
|
} );
|
|
|
|
|
return $mock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getNameTableSqlStore(
|
|
|
|
|
BagOStuff $cacheBag,
|
|
|
|
|
$insertCalls,
|
|
|
|
|
$selectCalls,
|
2018-06-11 10:52:31 +00:00
|
|
|
$normalizationCallback = null,
|
|
|
|
|
$insertCallback = null
|
2018-01-16 13:53:22 +00:00
|
|
|
) {
|
|
|
|
|
return new NameTableStore(
|
|
|
|
|
$this->getMockLoadBalancer( $this->getCallCheckingDb( $insertCalls, $selectCalls ) ),
|
|
|
|
|
$this->getHashWANObjectCache( $cacheBag ),
|
|
|
|
|
new NullLogger(),
|
|
|
|
|
'slot_roles', 'role_id', 'role_name',
|
2018-06-11 10:52:31 +00:00
|
|
|
$normalizationCallback,
|
|
|
|
|
false,
|
|
|
|
|
$insertCallback
|
2018-01-16 13:53:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetAndAcquireId() {
|
|
|
|
|
return [
|
|
|
|
|
'no wancache, empty table' =>
|
|
|
|
|
[ new EmptyBagOStuff(), true, 1, [], 'foo', 1 ],
|
|
|
|
|
'no wancache, one matching value' =>
|
|
|
|
|
[ new EmptyBagOStuff(), false, 1, [ 'foo' ], 'foo', 1 ],
|
|
|
|
|
'no wancache, one not matching value' =>
|
|
|
|
|
[ new EmptyBagOStuff(), true, 1, [ 'bar' ], 'foo', 2 ],
|
|
|
|
|
'no wancache, multiple, one matching value' =>
|
|
|
|
|
[ new EmptyBagOStuff(), false, 1, [ 'foo', 'bar' ], 'bar', 2 ],
|
|
|
|
|
'no wancache, multiple, no matching value' =>
|
|
|
|
|
[ new EmptyBagOStuff(), true, 1, [ 'foo', 'bar' ], 'baz', 3 ],
|
|
|
|
|
'wancache, empty table' =>
|
|
|
|
|
[ new HashBagOStuff(), true, 1, [], 'foo', 1 ],
|
|
|
|
|
'wancache, one matching value' =>
|
|
|
|
|
[ new HashBagOStuff(), false, 1, [ 'foo' ], 'foo', 1 ],
|
|
|
|
|
'wancache, one not matching value' =>
|
|
|
|
|
[ new HashBagOStuff(), true, 1, [ 'bar' ], 'foo', 2 ],
|
|
|
|
|
'wancache, multiple, one matching value' =>
|
|
|
|
|
[ new HashBagOStuff(), false, 1, [ 'foo', 'bar' ], 'bar', 2 ],
|
|
|
|
|
'wancache, multiple, no matching value' =>
|
|
|
|
|
[ new HashBagOStuff(), true, 1, [ 'foo', 'bar' ], 'baz', 3 ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetAndAcquireId
|
|
|
|
|
* @param BagOStuff $cacheBag to use in the WANObjectCache service
|
|
|
|
|
* @param bool $needsInsert Does the value we are testing need to be inserted?
|
|
|
|
|
* @param int $selectCalls Number of times the select DB method will be called
|
|
|
|
|
* @param string[] $existingValues to be added to the db table
|
|
|
|
|
* @param string $name name to acquire
|
|
|
|
|
* @param int $expectedId the id we expect the name to have
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAndAcquireId(
|
|
|
|
|
$cacheBag,
|
|
|
|
|
$needsInsert,
|
|
|
|
|
$selectCalls,
|
|
|
|
|
$existingValues,
|
|
|
|
|
$name,
|
|
|
|
|
$expectedId
|
|
|
|
|
) {
|
2018-08-22 16:02:49 +00:00
|
|
|
// Make sure the table is empty!
|
|
|
|
|
$this->truncateTable( 'slot_roles' );
|
|
|
|
|
|
2018-01-16 13:53:22 +00:00
|
|
|
$this->populateTable( $existingValues );
|
|
|
|
|
$store = $this->getNameTableSqlStore( $cacheBag, (int)$needsInsert, $selectCalls );
|
|
|
|
|
|
|
|
|
|
// Some names will not initially exist
|
|
|
|
|
try {
|
|
|
|
|
$result = $store->getId( $name );
|
|
|
|
|
$this->assertSame( $expectedId, $result );
|
|
|
|
|
} catch ( NameTableAccessException $e ) {
|
|
|
|
|
if ( $needsInsert ) {
|
|
|
|
|
$this->assertTrue( true ); // Expected exception
|
|
|
|
|
} else {
|
|
|
|
|
$this->fail( 'Did not expect an exception, but got one: ' . $e->getMessage() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All names should return their id here
|
|
|
|
|
$this->assertSame( $expectedId, $store->acquireId( $name ) );
|
|
|
|
|
|
|
|
|
|
// acquireId inserted these names, so now everything should exist with getId
|
|
|
|
|
$this->assertSame( $expectedId, $store->getId( $name ) );
|
|
|
|
|
|
|
|
|
|
// calling getId again will also still work, and not result in more selects
|
|
|
|
|
$this->assertSame( $expectedId, $store->getId( $name ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideTestGetAndAcquireIdNameNormalization() {
|
|
|
|
|
yield [ 'A', 'a', 'strtolower' ];
|
|
|
|
|
yield [ 'b', 'B', 'strtoupper' ];
|
|
|
|
|
yield [
|
|
|
|
|
'X',
|
|
|
|
|
'X',
|
|
|
|
|
function ( $name ) {
|
|
|
|
|
return $name;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
yield [ 'ZZ', 'ZZ-a', __CLASS__ . '::appendDashAToString' ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function appendDashAToString( $string ) {
|
|
|
|
|
return $string . '-a';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideTestGetAndAcquireIdNameNormalization
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAndAcquireIdNameNormalization(
|
|
|
|
|
$nameIn,
|
|
|
|
|
$nameOut,
|
|
|
|
|
$normalizationCallback
|
|
|
|
|
) {
|
|
|
|
|
$store = $this->getNameTableSqlStore(
|
|
|
|
|
new EmptyBagOStuff(),
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
$normalizationCallback
|
|
|
|
|
);
|
|
|
|
|
$acquiredId = $store->acquireId( $nameIn );
|
|
|
|
|
$this->assertSame( $nameOut, $store->getName( $acquiredId ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetName() {
|
|
|
|
|
return [
|
2019-02-27 01:04:24 +00:00
|
|
|
[ new HashBagOStuff(), 3, 2 ],
|
2018-01-16 13:53:22 +00:00
|
|
|
[ new EmptyBagOStuff(), 3, 3 ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetName
|
|
|
|
|
*/
|
2019-04-10 05:06:04 +00:00
|
|
|
public function testGetName( BagOStuff $cacheBag, $insertCalls, $selectCalls ) {
|
|
|
|
|
$now = microtime( true );
|
|
|
|
|
$cacheBag->setMockTime( $now );
|
2019-02-27 01:04:24 +00:00
|
|
|
// Check for operations to in-memory cache (IMC) and persistent cache (PC)
|
2018-01-16 13:53:22 +00:00
|
|
|
$store = $this->getNameTableSqlStore( $cacheBag, $insertCalls, $selectCalls );
|
|
|
|
|
|
|
|
|
|
// Get 1 ID and make sure getName returns correctly
|
2019-02-27 01:04:24 +00:00
|
|
|
$fooId = $store->acquireId( 'foo' ); // regen PC, set IMC, update IMC, tombstone PC
|
2019-04-10 05:06:04 +00:00
|
|
|
$now += 0.01;
|
2019-02-27 01:04:24 +00:00
|
|
|
$this->assertSame( 'foo', $store->getName( $fooId ) ); // use IMC
|
2019-04-10 05:06:04 +00:00
|
|
|
$now += 0.01;
|
2018-01-16 13:53:22 +00:00
|
|
|
|
|
|
|
|
// Get another ID and make sure getName returns correctly
|
2019-02-27 01:04:24 +00:00
|
|
|
$barId = $store->acquireId( 'bar' ); // update IMC, tombstone PC
|
2019-04-10 05:06:04 +00:00
|
|
|
$now += 0.01;
|
2019-02-27 01:04:24 +00:00
|
|
|
$this->assertSame( 'bar', $store->getName( $barId ) ); // use IMC
|
2019-04-10 05:06:04 +00:00
|
|
|
$now += 0.01;
|
2018-01-16 13:53:22 +00:00
|
|
|
|
|
|
|
|
// Blitz the cache and make sure it still returns
|
2019-02-27 01:04:24 +00:00
|
|
|
TestingAccessWrapper::newFromObject( $store )->tableCache = null; // clear IMC
|
|
|
|
|
$this->assertSame( 'foo', $store->getName( $fooId ) ); // regen interim PC, set IMC
|
|
|
|
|
$this->assertSame( 'bar', $store->getName( $barId ) ); // use IMC
|
2018-01-16 13:53:22 +00:00
|
|
|
|
|
|
|
|
// Blitz the cache again and get another ID and make sure getName returns correctly
|
2019-02-27 01:04:24 +00:00
|
|
|
TestingAccessWrapper::newFromObject( $store )->tableCache = null; // clear IMC
|
|
|
|
|
$bazId = $store->acquireId( 'baz' ); // set IMC using interim PC, update IMC, tombstone PC
|
2019-04-10 05:06:04 +00:00
|
|
|
$now += 0.01;
|
2019-02-27 01:04:24 +00:00
|
|
|
$this->assertSame( 'baz', $store->getName( $bazId ) ); // uses IMC
|
|
|
|
|
$this->assertSame( 'baz', $store->getName( $bazId ) ); // uses IMC
|
2018-01-16 13:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetName_masterFallback() {
|
|
|
|
|
$store = $this->getNameTableSqlStore( new EmptyBagOStuff(), 1, 2 );
|
|
|
|
|
|
|
|
|
|
// Insert a new name
|
|
|
|
|
$fooId = $store->acquireId( 'foo' );
|
|
|
|
|
|
|
|
|
|
// Empty the process cache, getCachedTable() will now return this empty array
|
|
|
|
|
TestingAccessWrapper::newFromObject( $store )->tableCache = [];
|
|
|
|
|
|
|
|
|
|
// getName should fallback to master, which is why we assert 2 selectCalls above
|
|
|
|
|
$this->assertSame( 'foo', $store->getName( $fooId ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetMap_empty() {
|
|
|
|
|
$this->populateTable( [] );
|
|
|
|
|
$store = $this->getNameTableSqlStore( new HashBagOStuff(), 0, 1 );
|
|
|
|
|
$table = $store->getMap();
|
|
|
|
|
$this->assertSame( [], $table );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetMap_twoValues() {
|
|
|
|
|
$this->populateTable( [ 'foo', 'bar' ] );
|
|
|
|
|
$store = $this->getNameTableSqlStore( new HashBagOStuff(), 0, 1 );
|
|
|
|
|
|
|
|
|
|
// We are using a cache, so 2 calls should only result in 1 select on the db
|
|
|
|
|
$store->getMap();
|
|
|
|
|
$table = $store->getMap();
|
|
|
|
|
|
2018-04-13 21:16:39 +00:00
|
|
|
$expected = [ 1 => 'foo', 2 => 'bar' ];
|
2018-01-16 13:53:22 +00:00
|
|
|
$this->assertSame( $expected, $table );
|
|
|
|
|
// Make sure the table returned is the same as the cached table
|
|
|
|
|
$this->assertSame( $expected, TestingAccessWrapper::newFromObject( $store )->tableCache );
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-22 16:02:49 +00:00
|
|
|
public function testReloadMap() {
|
|
|
|
|
$this->populateTable( [ 'foo' ] );
|
|
|
|
|
$store = $this->getNameTableSqlStore( new HashBagOStuff(), 0, 2 );
|
|
|
|
|
|
|
|
|
|
// force load
|
|
|
|
|
$this->assertCount( 1, $store->getMap() );
|
|
|
|
|
|
|
|
|
|
// add more stuff to the table, so the cache gets out of sync
|
|
|
|
|
$this->populateTable( [ 'bar' ] );
|
|
|
|
|
|
|
|
|
|
$expected = [ 1 => 'foo', 2 => 'bar' ];
|
|
|
|
|
$this->assertSame( $expected, $store->reloadMap() );
|
|
|
|
|
$this->assertSame( $expected, $store->getMap() );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 13:53:22 +00:00
|
|
|
public function testCacheRaceCondition() {
|
|
|
|
|
$wanHashBag = new HashBagOStuff();
|
|
|
|
|
$store1 = $this->getNameTableSqlStore( $wanHashBag, 1, 1 );
|
|
|
|
|
$store2 = $this->getNameTableSqlStore( $wanHashBag, 1, 0 );
|
|
|
|
|
$store3 = $this->getNameTableSqlStore( $wanHashBag, 1, 1 );
|
|
|
|
|
|
|
|
|
|
// Cache the current table in the instances we will use
|
|
|
|
|
// This simulates multiple requests running simultaneously
|
|
|
|
|
$store1->getMap();
|
|
|
|
|
$store2->getMap();
|
|
|
|
|
$store3->getMap();
|
|
|
|
|
|
|
|
|
|
// Store 2 separate names using different instances
|
|
|
|
|
$fooId = $store1->acquireId( 'foo' );
|
|
|
|
|
$barId = $store2->acquireId( 'bar' );
|
|
|
|
|
|
|
|
|
|
// Each of these instances should be aware of what they have inserted
|
|
|
|
|
$this->assertSame( $fooId, $store1->acquireId( 'foo' ) );
|
|
|
|
|
$this->assertSame( $barId, $store2->acquireId( 'bar' ) );
|
|
|
|
|
|
|
|
|
|
// A new store should be able to get both of these new Ids
|
|
|
|
|
// Note: before there was a race condition here where acquireId( 'bar' ) would update the
|
|
|
|
|
// cache with data missing the 'foo' key that it was not aware of
|
|
|
|
|
$store4 = $this->getNameTableSqlStore( $wanHashBag, 0, 1 );
|
|
|
|
|
$this->assertSame( $fooId, $store4->getId( 'foo' ) );
|
|
|
|
|
$this->assertSame( $barId, $store4->getId( 'bar' ) );
|
|
|
|
|
|
|
|
|
|
// If a store with old cached data tries to acquire these we will get the same ids.
|
|
|
|
|
$this->assertSame( $fooId, $store3->acquireId( 'foo' ) );
|
|
|
|
|
$this->assertSame( $barId, $store3->acquireId( 'bar' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-11 10:52:31 +00:00
|
|
|
public function testGetAndAcquireIdInsertCallback() {
|
2018-08-01 07:25:32 +00:00
|
|
|
// FIXME: fails under postgres
|
|
|
|
|
$this->markTestSkippedIfDbType( 'postgres' );
|
|
|
|
|
|
2018-06-11 10:52:31 +00:00
|
|
|
$store = $this->getNameTableSqlStore(
|
|
|
|
|
new EmptyBagOStuff(),
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
null,
|
|
|
|
|
function ( $insertFields ) {
|
|
|
|
|
$insertFields['role_id'] = 7251;
|
|
|
|
|
return $insertFields;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame( 7251, $store->acquireId( 'A' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 13:53:22 +00:00
|
|
|
}
|