* @covers DeferredUpdates::addUpdate
* @covers DeferredUpdates::push
* @covers DeferredUpdates::doUpdates
- * @covers DeferredUpdates::execute
- * @covers DeferredUpdates::runUpdate
+ * @covers DeferredUpdates::handleUpdateQueue
+ * @covers DeferredUpdates::attemptUpdate
*/
public function testAddAndRun() {
$update = $this->getMockBuilder( DeferrableUpdate::class )
/**
* @covers DeferredUpdates::doUpdates
- * @covers DeferredUpdates::execute
+ * @covers DeferredUpdates::handleUpdateQueue
* @covers DeferredUpdates::addUpdate
*/
public function testDoUpdatesWeb() {
/**
* @covers DeferredUpdates::doUpdates
- * @covers DeferredUpdates::execute
+ * @covers DeferredUpdates::handleUpdateQueue
* @covers DeferredUpdates::addUpdate
*/
public function testDoUpdatesCLI() {
];
// clear anything
- wfGetLBFactory()->commitMasterChanges( __METHOD__ );
+ $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ $lbFactory->commitMasterChanges( __METHOD__ );
DeferredUpdates::addCallableUpdate(
function () use ( $updates ) {
/**
* @covers DeferredUpdates::doUpdates
- * @covers DeferredUpdates::execute
+ * @covers DeferredUpdates::handleUpdateQueue
* @covers DeferredUpdates::addUpdate
*/
public function testPresendAddOnPostsendRun() {
$x = false;
$y = false;
// clear anything
- wfGetLBFactory()->commitMasterChanges( __METHOD__ );
+ $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ $lbFactory->commitMasterChanges( __METHOD__ );
DeferredUpdates::addCallableUpdate(
function () use ( &$x, &$y ) {
}
/**
- * @covers DeferredUpdates::runUpdate
+ * @covers DeferredUpdates::attemptUpdate
*/
public function testRunUpdateTransactionScope() {
$this->setMwGlobals( 'wgCommandLineMode', false );
}
/**
- * @covers DeferredUpdates::runUpdate
+ * @covers DeferredUpdates::attemptUpdate
* @covers TransactionRoundDefiningUpdate::getOrigin
*/
public function testRunOuterScopeUpdate() {
$ran = 0;
DeferredUpdates::addUpdate( new TransactionRoundDefiningUpdate(
- function () use ( &$ran, $lbFactory ) {
- $ran++;
- $this->assertFalse( $lbFactory->hasTransactionRound(), 'No transaction' );
- } )
+ function () use ( &$ran, $lbFactory ) {
+ $ran++;
+ $this->assertFalse( $lbFactory->hasTransactionRound(), 'No transaction' );
+ } )
);
DeferredUpdates::doUpdates();
$this->assertSame( 1, $ran, 'Update ran' );
}
+
+ /**
+ * @covers DeferredUpdates::tryOpportunisticExecute
+ */
+ public function testTryOpportunisticExecute() {
+ $calls = [];
+ $callback1 = function () use ( &$calls ) {
+ $calls[] = 1;
+ };
+ $callback2 = function () use ( &$calls ) {
+ $calls[] = 2;
+ };
+
+ $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ $lbFactory->beginMasterChanges( __METHOD__ );
+
+ DeferredUpdates::addCallableUpdate( $callback1 );
+ $this->assertEquals( [], $calls );
+
+ DeferredUpdates::tryOpportunisticExecute( 'run' );
+ $this->assertEquals( [], $calls );
+
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->onTransactionCommitOrIdle( function () use ( &$calls, $callback2 ) {
+ DeferredUpdates::addCallableUpdate( $callback2 );
+ $this->assertEquals( [], $calls );
+ $calls[] = 'oti';
+ } );
+ $this->assertEquals( 1, $dbw->trxLevel() );
+ $this->assertEquals( [], $calls );
+
+ $lbFactory->commitMasterChanges( __METHOD__ );
+
+ $this->assertEquals( [ 'oti' ], $calls );
+
+ DeferredUpdates::tryOpportunisticExecute( 'run' );
+ $this->assertEquals( [ 'oti', 1, 2 ], $calls );
+ }
}