From a430307fadf99c376717a3aca8ffae1365b15e7f Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 29 Mar 2018 22:14:55 +0200 Subject: [PATCH] Make DeferredUpdates re-throw exceptions during testing. 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 | 42 +++++++++++++++++---------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/includes/deferred/DeferredUpdates.php b/includes/deferred/DeferredUpdates.php index 9b25d53820..ef46953432 100644 --- a/includes/deferred/DeferredUpdates.php +++ b/includes/deferred/DeferredUpdates.php @@ -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; -- 2.20.1