16 ->setMethods( [
'doUpdate' ] )->getMock();
17 $update->expects( $this->once() )->method(
'doUpdate' );
31 ->setMethods( [
'merge',
'doUpdate' ] )->getMock();
32 $update1->expects( $this->once() )->method(
'merge' );
33 $update1->expects( $this->never() )->method(
'doUpdate' );
36 ->setMethods( [
'merge',
'doUpdate' ] )->getMock();
37 $update2->expects( $this->never() )->method(
'merge' );
38 $update2->expects( $this->never() )->method(
'doUpdate' );
57 $this->assertSame( 1, $ran,
'Update ran' );
73 $update->expects( $this->never() )
74 ->method(
'doUpdate' );
102 '1' =>
"deferred update 1;\n",
103 '2' =>
"deferred update 2;\n",
104 '2-1' =>
"deferred update 1 within deferred update 2;\n",
105 '2-2' =>
"deferred update 2 within deferred update 2;\n",
106 '3' =>
"deferred update 3;\n",
107 '3-1' =>
"deferred update 1 within deferred update 3;\n",
108 '3-2' =>
"deferred update 2 within deferred update 3;\n",
109 '3-1-1' =>
"deferred update 1 within deferred update 1 within deferred update 3;\n",
110 '3-2-1' =>
"deferred update 1 within deferred update 2 with deferred update 3;\n",
113 function ()
use ( $updates ) {
118 function ()
use ( $updates ) {
121 function ()
use ( $updates ) {
122 echo $updates[
'2-1'];
126 function ()
use ( $updates ) {
127 echo $updates[
'2-2'];
133 function ()
use ( $updates ) {
136 function ()
use ( $updates ) {
137 echo $updates[
'3-1'];
139 function ()
use ( $updates ) {
140 echo $updates[
'3-1-1'];
146 function ()
use ( $updates ) {
147 echo $updates[
'3-2'];
149 function ()
use ( $updates ) {
150 echo $updates[
'3-2-1'];
160 $this->expectOutputString( implode(
'', $updates ) );
167 function ()
use ( &$x ) {
173 function ()
use ( &$y ) {
179 $this->assertNull( $x,
"Update not run yet" );
180 $this->assertNull( $y,
"Update not run yet" );
183 $this->assertEquals(
"Sherity", $x,
"PRESEND update ran" );
184 $this->assertNull( $y,
"POSTSEND update not run yet" );
187 $this->assertEquals(
"Marychu", $y,
"POSTSEND update ran" );
198 '1' =>
"deferred update 1;\n",
199 '2' =>
"deferred update 2;\n",
200 '2-1' =>
"deferred update 1 within deferred update 2;\n",
201 '2-2' =>
"deferred update 2 within deferred update 2;\n",
202 '3' =>
"deferred update 3;\n",
203 '3-1' =>
"deferred update 1 within deferred update 3;\n",
204 '3-2' =>
"deferred update 2 within deferred update 3;\n",
205 '3-1-1' =>
"deferred update 1 within deferred update 1 within deferred update 3;\n",
206 '3-2-1' =>
"deferred update 1 within deferred update 2 with deferred update 3;\n",
210 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
211 $lbFactory->commitMasterChanges( __METHOD__ );
214 function ()
use ( $updates ) {
219 function ()
use ( $updates ) {
222 function ()
use ( $updates ) {
223 echo $updates[
'2-1'];
227 function ()
use ( $updates ) {
228 echo $updates[
'2-2'];
234 function ()
use ( $updates ) {
237 function ()
use ( $updates ) {
238 echo $updates[
'3-1'];
240 function ()
use ( $updates ) {
241 echo $updates[
'3-1-1'];
247 function ()
use ( $updates ) {
248 echo $updates[
'3-2'];
250 function ()
use ( $updates ) {
251 echo $updates[
'3-2-1'];
259 $this->expectOutputString( implode(
'', $updates ) );
275 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
276 $lbFactory->commitMasterChanges( __METHOD__ );
279 function ()
use ( &$x, &$y ) {
282 function ()
use ( &$y ) {
293 $this->assertTrue( $x,
"Outer POSTSEND update ran" );
294 $this->assertTrue( $y,
"Nested PRESEND update ran" );
303 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
304 $this->assertFalse( $lbFactory->hasTransactionRound(),
'Initial state' );
309 $this->assertTrue( $lbFactory->hasTransactionRound(),
'Has transaction' );
313 $this->assertSame( 1, $ran,
'Update ran' );
314 $this->assertFalse( $lbFactory->hasTransactionRound(),
'Final state' );
324 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
325 $this->assertFalse( $lbFactory->hasTransactionRound(),
'Initial state' );
329 function ()
use ( &$ran, $lbFactory ) {
331 $this->assertFalse( $lbFactory->hasTransactionRound(),
'No transaction' );
336 $this->assertSame( 1, $ran,
'Update ran' );
344 $callback1 =
function ()
use ( &$calls ) {
347 $callback2 =
function ()
use ( &$calls ) {
351 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
352 $lbFactory->beginMasterChanges( __METHOD__ );
355 $this->assertEquals( [], $calls );
358 $this->assertEquals( [], $calls );
361 $dbw->onTransactionCommitOrIdle(
function ()
use ( &$calls, $callback2 ) {
363 $this->assertEquals( [], $calls );
366 $this->assertEquals( 1, $dbw->trxLevel() );
367 $this->assertEquals( [], $calls );
369 $lbFactory->commitMasterChanges( __METHOD__ );
371 $this->assertEquals( [
'oti' ], $calls );
374 $this->assertEquals( [
'oti', 1, 2 ], $calls );