}
/**
- * @covers Wikimedia\Rdbms\Database::onTransactionIdle
+ * @covers Wikimedia\Rdbms\Database::onTransactionCommitOrIdle
* @covers Wikimedia\Rdbms\Database::runOnTransactionIdleCallbacks
*/
public function testTransactionIdle() {
$flagSet = $db->getFlag( DBO_TRX );
};
- $db->onTransactionIdle( $callback, __METHOD__ );
+ $db->onTransactionCommitOrIdle( $callback, __METHOD__ );
$this->assertTrue( $called, 'Callback reached' );
$this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
$this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX still default' );
$flagSet = null;
$called = false;
$db->startAtomic( __METHOD__ );
- $db->onTransactionIdle( $callback, __METHOD__ );
+ $db->onTransactionCommitOrIdle( $callback, __METHOD__ );
$this->assertFalse( $called, 'Callback not reached during TRX' );
$db->endAtomic( __METHOD__ );
$this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored to default' );
$db->clearFlag( DBO_TRX );
- $db->onTransactionIdle(
+ $db->onTransactionCommitOrIdle(
function ( $trigger, IDatabase $db ) {
$db->setFlag( DBO_TRX );
},
}
/**
- * @covers Wikimedia\Rdbms\Database::onTransactionIdle
+ * @covers Wikimedia\Rdbms\Database::onTransactionCommitOrIdle
* @covers Wikimedia\Rdbms\Database::runOnTransactionIdleCallbacks
*/
public function testTransactionIdle_TRX() {
$flagSet = $db->getFlag( DBO_TRX );
};
- $db->onTransactionIdle( $callback, __METHOD__ );
+ $db->onTransactionCommitOrIdle( $callback, __METHOD__ );
$this->assertTrue( $called, 'Called when idle if DBO_TRX is set' );
$this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
$this->assertTrue( $db->getFlag( DBO_TRX ), 'DBO_TRX still default' );
$called = false;
$lbFactory->beginMasterChanges( __METHOD__ );
- $db->onTransactionIdle( $callback, __METHOD__ );
+ $db->onTransactionCommitOrIdle( $callback, __METHOD__ );
$this->assertFalse( $called, 'Not called when lb-transaction is active' );
$lbFactory->commitMasterChanges( __METHOD__ );
$called = false;
$lbFactory->beginMasterChanges( __METHOD__ );
- $db->onTransactionIdle( $callback, __METHOD__ );
+ $db->onTransactionCommitOrIdle( $callback, __METHOD__ );
$this->assertFalse( $called, 'Not called when lb-transaction is active' );
$lbFactory->rollbackMasterChanges( __METHOD__ );
$lbFactory->commitMasterChanges( __METHOD__ );
$this->assertFalse( $called, 'Not called in next round commit' );
+
+ $db->setFlag( DBO_TRX );
+ try {
+ $db->onTransactionCommitOrIdle( function () {
+ throw new RuntimeException( 'test' );
+ } );
+ $this->fail( "Exception not thrown" );
+ } catch ( RuntimeException $e ) {
+ $this->assertTrue( $db->getFlag( DBO_TRX ) );
+ }
}
/**