X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Flibs%2Frdbms%2Fdatabase%2FDatabaseMysqlBaseTest.php;h=9f8c11a1bec33c6a65c66e3fdc16514d6b4b7495;hp=5e59cfdb78c4be057185c9fdb94f36b160969c37;hb=63d96c15fde8d4d2842aa50c5ed2ce594aa0c674;hpb=38ab0b0c4cb041d9c4ff0ca4b62656d2768df79a diff --git a/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php b/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php index 5e59cfdb78..9f8c11a1be 100644 --- a/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php +++ b/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php @@ -27,6 +27,7 @@ use Wikimedia\Rdbms\TransactionProfiler; use Wikimedia\Rdbms\DatabaseDomain; use Wikimedia\Rdbms\MySQLMasterPos; use Wikimedia\Rdbms\DatabaseMysqlBase; +use Wikimedia\Rdbms\DatabaseMysqli; use Wikimedia\Rdbms\Database; /** @@ -52,6 +53,9 @@ class FakeDatabaseMysqlBase extends DatabaseMysqlBase { protected function doQuery( $sql ) { } + protected function fetchAffectedRowCount() { + } + // From DatabaseMysqli protected function mysqlConnect( $realServer ) { } @@ -105,7 +109,7 @@ class FakeDatabaseMysqlBase extends DatabaseMysqlBase { } } -class DatabaseMysqlBaseTest extends PHPUnit_Framework_TestCase { +class DatabaseMysqlBaseTest extends PHPUnit\Framework\TestCase { use MediaWikiCoversValidator; @@ -176,7 +180,7 @@ class DatabaseMysqlBaseTest extends PHPUnit_Framework_TestCase { } private function getMockForViews() { - $db = $this->getMockBuilder( 'DatabaseMysqli' ) + $db = $this->getMockBuilder( DatabaseMysqli::class ) ->disableOriginalConstructor() ->setMethods( [ 'fetchRow', 'query' ] ) ->getMock(); @@ -212,17 +216,32 @@ class DatabaseMysqlBaseTest extends PHPUnit_Framework_TestCase { $db->listViews( '' ) ); } + public function testBinLogName() { + $pos = new MySQLMasterPos( "db1052.2424/4643", 1 ); + + $this->assertEquals( "db1052", $pos->binlog ); + $this->assertEquals( "db1052.2424", $pos->getLogFile() ); + $this->assertEquals( [ 2424, 4643 ], $pos->pos ); + } + /** * @dataProvider provideComparePositions * @covers Wikimedia\Rdbms\MySQLMasterPos */ - public function testHasReached( MySQLMasterPos $lowerPos, MySQLMasterPos $higherPos, $match ) { + public function testHasReached( + MySQLMasterPos $lowerPos, MySQLMasterPos $higherPos, $match, $hetero + ) { if ( $match ) { $this->assertTrue( $lowerPos->channelsMatch( $higherPos ) ); - $this->assertTrue( $higherPos->hasReached( $lowerPos ) ); - $this->assertTrue( $higherPos->hasReached( $higherPos ) ); + if ( $hetero ) { + // Each position is has one channel higher than the other + $this->assertFalse( $higherPos->hasReached( $lowerPos ) ); + } else { + $this->assertTrue( $higherPos->hasReached( $lowerPos ) ); + } $this->assertTrue( $lowerPos->hasReached( $lowerPos ) ); + $this->assertTrue( $higherPos->hasReached( $higherPos ) ); $this->assertFalse( $lowerPos->hasReached( $higherPos ) ); } else { // channels don't match $this->assertFalse( $lowerPos->channelsMatch( $higherPos ) ); @@ -233,53 +252,100 @@ class DatabaseMysqlBaseTest extends PHPUnit_Framework_TestCase { } public static function provideComparePositions() { + $now = microtime( true ); + return [ // Binlog style [ - new MySQLMasterPos( 'db1034-bin.000976', '843431247' ), - new MySQLMasterPos( 'db1034-bin.000976', '843431248' ), - true + new MySQLMasterPos( 'db1034-bin.000976/843431247', $now ), + new MySQLMasterPos( 'db1034-bin.000976/843431248', $now ), + true, + false ], [ - new MySQLMasterPos( 'db1034-bin.000976', '999' ), - new MySQLMasterPos( 'db1034-bin.000976', '1000' ), - true + new MySQLMasterPos( 'db1034-bin.000976/999', $now ), + new MySQLMasterPos( 'db1034-bin.000976/1000', $now ), + true, + false ], [ - new MySQLMasterPos( 'db1034-bin.000976', '999' ), - new MySQLMasterPos( 'db1035-bin.000976', '1000' ), + new MySQLMasterPos( 'db1034-bin.000976/999', $now ), + new MySQLMasterPos( 'db1035-bin.000976/1000', $now ), + false, false ], // MySQL GTID style [ - new MySQLMasterPos( 'db1-bin.2', '1', '3E11FA47-71CA-11E1-9E33-C80AA9429562:23' ), - new MySQLMasterPos( 'db1-bin.2', '2', '3E11FA47-71CA-11E1-9E33-C80AA9429562:24' ), - true + new MySQLMasterPos( '3E11FA47-71CA-11E1-9E33-C80AA9429562:23', $now ), + new MySQLMasterPos( '3E11FA47-71CA-11E1-9E33-C80AA9429562:24', $now ), + true, + false ], [ - new MySQLMasterPos( 'db1-bin.2', '1', '3E11FA47-71CA-11E1-9E33-C80AA9429562:99' ), - new MySQLMasterPos( 'db1-bin.2', '2', '3E11FA47-71CA-11E1-9E33-C80AA9429562:100' ), - true + new MySQLMasterPos( '3E11FA47-71CA-11E1-9E33-C80AA9429562:99', $now ), + new MySQLMasterPos( '3E11FA47-71CA-11E1-9E33-C80AA9429562:100', $now ), + true, + false ], [ - new MySQLMasterPos( 'db1-bin.2', '1', '3E11FA47-71CA-11E1-9E33-C80AA9429562:99' ), - new MySQLMasterPos( 'db1-bin.2', '2', '1E11FA47-71CA-11E1-9E33-C80AA9429562:100' ), + new MySQLMasterPos( '3E11FA47-71CA-11E1-9E33-C80AA9429562:99', $now ), + new MySQLMasterPos( '1E11FA47-71CA-11E1-9E33-C80AA9429562:100', $now ), + false, false ], // MariaDB GTID style [ - new MySQLMasterPos( 'db1-bin.2', '1', '255-11-23' ), - new MySQLMasterPos( 'db1-bin.2', '2', '255-11-24' ), - true + new MySQLMasterPos( '255-11-23', $now ), + new MySQLMasterPos( '255-11-24', $now ), + true, + false + ], + [ + new MySQLMasterPos( '255-11-99', $now ), + new MySQLMasterPos( '255-11-100', $now ), + true, + false + ], + [ + new MySQLMasterPos( '255-11-999', $now ), + new MySQLMasterPos( '254-11-1000', $now ), + false, + false ], [ - new MySQLMasterPos( 'db1-bin.2', '1', '255-11-99' ), - new MySQLMasterPos( 'db1-bin.2', '2', '255-11-100' ), + new MySQLMasterPos( '255-11-23,256-12-50', $now ), + new MySQLMasterPos( '255-11-24', $now ), + true, + false + ], + [ + new MySQLMasterPos( '255-11-99,256-12-50,257-12-50', $now ), + new MySQLMasterPos( '255-11-1000', $now ), + true, + false + ], + [ + new MySQLMasterPos( '255-11-23,256-12-50', $now ), + new MySQLMasterPos( '255-11-24,155-52-63', $now ), + true, + false + ], + [ + new MySQLMasterPos( '255-11-99,256-12-50,257-12-50', $now ), + new MySQLMasterPos( '255-11-1000,256-12-51', $now ), + true, + false + ], + [ + new MySQLMasterPos( '255-11-99,256-12-50', $now ), + new MySQLMasterPos( '255-13-1000,256-14-49', $now ), + true, true ], [ - new MySQLMasterPos( 'db1-bin.2', '1', '255-11-999' ), - new MySQLMasterPos( 'db1-bin.2', '2', '254-11-1000' ), + new MySQLMasterPos( '253-11-999,255-11-999', $now ), + new MySQLMasterPos( '254-11-1000', $now ), + false, false ], ]; @@ -292,28 +358,33 @@ class DatabaseMysqlBaseTest extends PHPUnit_Framework_TestCase { public function testChannelsMatch( MySQLMasterPos $pos1, MySQLMasterPos $pos2, $matches ) { $this->assertEquals( $matches, $pos1->channelsMatch( $pos2 ) ); $this->assertEquals( $matches, $pos2->channelsMatch( $pos1 ) ); + + $roundtripPos = new MySQLMasterPos( (string)$pos1, 1 ); + $this->assertEquals( (string)$pos1, (string)$roundtripPos ); } public static function provideChannelPositions() { + $now = microtime( true ); + return [ [ - new MySQLMasterPos( 'db1034-bin.000876', '44' ), - new MySQLMasterPos( 'db1034-bin.000976', '74' ), + new MySQLMasterPos( 'db1034-bin.000876/44', $now ), + new MySQLMasterPos( 'db1034-bin.000976/74', $now ), true ], [ - new MySQLMasterPos( 'db1052-bin.000976', '999' ), - new MySQLMasterPos( 'db1052-bin.000976', '1000' ), + new MySQLMasterPos( 'db1052-bin.000976/999', $now ), + new MySQLMasterPos( 'db1052-bin.000976/1000', $now ), true ], [ - new MySQLMasterPos( 'db1066-bin.000976', '9999' ), - new MySQLMasterPos( 'db1035-bin.000976', '10000' ), + new MySQLMasterPos( 'db1066-bin.000976/9999', $now ), + new MySQLMasterPos( 'db1035-bin.000976/10000', $now ), false ], [ - new MySQLMasterPos( 'db1066-bin.000976', '9999' ), - new MySQLMasterPos( 'trump2016.000976', '10000' ), + new MySQLMasterPos( 'db1066-bin.000976/9999', $now ), + new MySQLMasterPos( 'trump2016.000976/10000', $now ), false ], ]; @@ -325,7 +396,7 @@ class DatabaseMysqlBaseTest extends PHPUnit_Framework_TestCase { * @covers Wikimedia\Rdbms\DatabaseMysqlBase::getLagFromPtHeartbeat */ public function testPtHeartbeat( $lag ) { - $db = $this->getMockBuilder( 'DatabaseMysqli' ) + $db = $this->getMockBuilder( DatabaseMysqli::class ) ->disableOriginalConstructor() ->setMethods( [ 'getLagDetectionMethod', 'getHeartbeatData', 'getMasterServerInfo' ] )