Make DeferredUpdates re-throw exceptions during testing.
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 29 Mar 2018 20:14:55 +0000 (22:14 +0200)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 2 May 2018 21:16:05 +0000 (21:16 +0000)
This is a stop-gap solution for the problem described in T190178.
A better solution would probably include changing the behavior
of LegacyLogger.

Bug: T190178
Change-Id: I433be04b8ee725becd174e567270aa674d2661df

includes/deferred/DeferredUpdates.php

index 9b25d53..ef46953 100644 (file)
@@ -206,23 +206,29 @@ class DeferredUpdates {
                        foreach ( $updatesByType as $updatesForType ) {
                                foreach ( $updatesForType as $update ) {
                                        self::$executeContext = [ 'stage' => $stage, 'subqueue' => [] ];
-                                       /** @var DeferrableUpdate $update */
-                                       $guiError = self::runUpdate( $update, $lbFactory, $mode, $stage );
-                                       $reportableError = $reportableError ?: $guiError;
-                                       // Do the subqueue updates for $update until there are none
-                                       while ( self::$executeContext['subqueue'] ) {
-                                               $subUpdate = reset( self::$executeContext['subqueue'] );
-                                               $firstKey = key( self::$executeContext['subqueue'] );
-                                               unset( self::$executeContext['subqueue'][$firstKey] );
-
-                                               if ( $subUpdate instanceof DataUpdate ) {
-                                                       $subUpdate->setTransactionTicket( $ticket );
-                                               }
-
-                                               $guiError = self::runUpdate( $subUpdate, $lbFactory, $mode, $stage );
+                                       try {
+                                               /** @var DeferrableUpdate $update */
+                                               $guiError = self::runUpdate( $update, $lbFactory, $mode, $stage );
                                                $reportableError = $reportableError ?: $guiError;
+                                               // Do the subqueue updates for $update until there are none
+                                               while ( self::$executeContext['subqueue'] ) {
+                                                       $subUpdate = reset( self::$executeContext['subqueue'] );
+                                                       $firstKey = key( self::$executeContext['subqueue'] );
+                                                       unset( self::$executeContext['subqueue'][$firstKey] );
+
+                                                       if ( $subUpdate instanceof DataUpdate ) {
+                                                               $subUpdate->setTransactionTicket( $ticket );
+                                                       }
+
+                                                       $guiError = self::runUpdate( $subUpdate, $lbFactory, $mode, $stage );
+                                                       $reportableError = $reportableError ?: $guiError;
+                                               }
+                                       } finally {
+                                               // Make sure we always clean up the context.
+                                               // Losing updates while rewinding the stack is acceptable,
+                                               // losing updates that are added later is not.
+                                               self::$executeContext = null;
                                        }
-                                       self::$executeContext = null;
                                }
                        }
 
@@ -265,6 +271,12 @@ class DeferredUpdates {
                                $guiError = $e;
                        }
                        MWExceptionHandler::rollbackMasterChangesAndLog( $e );
+
+                       // VW-style hack to work around T190178, so we can make sure
+                       // PageMetaDataUpdater doesn't throw exceptions.
+                       if ( defined( 'MW_PHPUNIT_TEST' ) ) {
+                               throw $e;
+                       }
                }
 
                return $guiError;