Hashar has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/330183 )
Change subject: ¡Ándale! ¡Arriba! ¡Arriba! ¡Epa! ¡Epa! ...................................................................... ¡Ándale! ¡Arriba! ¡Arriba! ¡Epa! ¡Epa! Friz Freleng & Hawley Pratt -- 1955 Really: require test to explicity run deferred updates. Change-Id: I41fc8e9f548a879ead192cd013c6a7fc604113b8 --- M includes/deferred/DeferredUpdates.php M tests/phpunit/MediaWikiTestCase.php M tests/phpunit/includes/EditPageTest.php M tests/phpunit/includes/TemplateCategoriesTest.php M tests/phpunit/includes/WatchedItemIntegrationTest.php M tests/phpunit/includes/WatchedItemStoreIntegrationTest.php M tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php M tests/phpunit/includes/api/ApiQueryWatchlistRawIntegrationTest.php M tests/phpunit/includes/api/ApiTestCase.php M tests/phpunit/includes/deferred/LinksUpdateTest.php M tests/phpunit/includes/jobqueue/RefreshLinksPartitionTest.php M tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php M tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php M tests/phpunit/includes/page/ArticleTablesTest.php M tests/phpunit/includes/page/WikiPageTest.php 15 files changed, 66 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/83/330183/1 diff --git a/includes/deferred/DeferredUpdates.php b/includes/deferred/DeferredUpdates.php index 1ba6c1f..2dec642 100644 --- a/includes/deferred/DeferredUpdates.php +++ b/includes/deferred/DeferredUpdates.php @@ -54,6 +54,8 @@ private static $postSendUpdates = []; /** @var bool Whether to just run updates in addUpdate() */ private static $immediateMode = false; + /** @var bool Whether to try running updates when possible */ + private static $opportunisticMode = true; const ALL = 0; // all updates; in web requests, use only after flushing the output buffer const PRESEND = 1; // for updates that should run before flushing output buffer @@ -140,6 +142,14 @@ */ public static function setImmediateMode( $value ) { self::$immediateMode = (bool)$value; + } + + /** + * @param bool $value Whether to try running updates when possible + * @since 1.29 + */ + public static function setOpportunisticMode( $value ) { + self::$opportunisticMode = (bool)$value; } /** @@ -289,6 +299,10 @@ return false; } + if ( !self::$opportunisticMode ) { + return false; + } + // Avoiding running updates without them having outer scope if ( !self::getBusyDbConnections() ) { self::doUpdates( $mode ); diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index fd02a3e..9b88e5b 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -494,6 +494,9 @@ } DeferredUpdates::clearPendingUpdates(); + DeferredUpdates::setImmediateMode( false ); + DeferredUpdates::setOpportunisticMode( false ); + ObjectCache::getMainWANInstance()->clearProcessCache(); // XXX: reset maintenance triggers @@ -967,6 +970,7 @@ $page = WikiPage::factory( $title ); $page->doEditContent( ContentHandler::makeContent( $text, $title ), $comment, 0, false, $user ); + DeferredUpdates::doUpdates(); return [ 'title' => $title, diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index 5a01dc0..bf4cba4 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -297,6 +297,7 @@ } $page = $this->assertEdit( $pageTitle, null, $user, $edit, $expectedCode, $expectedText, $desc ); + DeferredUpdates::doUpdates(); if ( $expectedCode != EditPage::AS_BLANK_ARTICLE ) { $latest = $page->getLatest(); @@ -348,6 +349,7 @@ wfGetDB( DB_MASTER )->commit( __METHOD__ ); + DeferredUpdates::doUpdates(); $this->assertEquals( 0, DeferredUpdates::pendingUpdatesCount(), 'No deferred updates' ); if ( $expectedCode != EditPage::AS_BLANK_ARTICLE ) { @@ -394,6 +396,8 @@ $page = $this->assertEdit( 'EditPageTest_testUpdatePage', "zero", null, $edit, EditPage::AS_SUCCESS_UPDATE, $text, "expected successfull update with given text" ); + DeferredUpdates::doUpdates(); + $this->assertGreaterThan( 0, $checkIds[0], "First event rev ID set" ); $this->forceRevisionDate( $page, '20120101000000' ); @@ -460,6 +464,8 @@ wfGetDB( DB_MASTER )->commit( __METHOD__ ); + DeferredUpdates::doUpdates(); + $this->assertGreaterThan( 0, $checkIds[0], "First event rev ID set" ); $this->assertGreaterThan( 0, $checkIds[1], "Second edit hook rev ID set" ); $this->assertGreaterThan( $checkIds[0], $checkIds[1], "Second event rev ID is higher" ); diff --git a/tests/phpunit/includes/TemplateCategoriesTest.php b/tests/phpunit/includes/TemplateCategoriesTest.php index 152602a..ecbf52c 100644 --- a/tests/phpunit/includes/TemplateCategoriesTest.php +++ b/tests/phpunit/includes/TemplateCategoriesTest.php @@ -62,6 +62,8 @@ $user ); + DeferredUpdates::doUpdates(); + // Run the job queue JobQueueGroup::destroySingletons(); $jobs = new RunJobs; diff --git a/tests/phpunit/includes/WatchedItemIntegrationTest.php b/tests/phpunit/includes/WatchedItemIntegrationTest.php index 65a8c86..a2e76f7 100644 --- a/tests/phpunit/includes/WatchedItemIntegrationTest.php +++ b/tests/phpunit/includes/WatchedItemIntegrationTest.php @@ -58,6 +58,7 @@ $this->assertNull( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() ); EmailNotification::updateWatchlistTimestamp( $otherUser, $title, '20150202010101' ); + DeferredUpdates::doUpdates(); $this->assertEquals( '20150202010101', WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() @@ -66,6 +67,7 @@ MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp( $user, $title ); + DeferredUpdates::doUpdates(); $this->assertNull( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() ); } diff --git a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php index 61b62aa..1b37990 100644 --- a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php +++ b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php @@ -117,6 +117,8 @@ $initialUnreadNotifications = $store->countUnreadNotifications( $user ); $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' ); + DeferredUpdates::doUpdates(); + $this->assertEquals( '20150202010101', $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() @@ -145,6 +147,8 @@ ); $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) ); + DeferredUpdates::doUpdates(); + $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() ); $this->assertEquals( [ $title->getNamespace() => [ $title->getDBkey() => null ] ], diff --git a/tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php b/tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php index 0a2cd83..3d6217e 100644 --- a/tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php +++ b/tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php @@ -44,6 +44,7 @@ false, $user ); + DeferredUpdates::doUpdates(); } private function doMinorPageEdit( User $user, LinkTarget $target, $content, $summary ) { @@ -56,6 +57,7 @@ false, $user ); + DeferredUpdates::doUpdates(); } private function doBotPageEdit( User $user, LinkTarget $target, $content, $summary ) { @@ -68,6 +70,7 @@ false, $user ); + DeferredUpdates::doUpdates(); } private function doAnonPageEdit( LinkTarget $target, $content, $summary ) { @@ -80,6 +83,7 @@ false, User::newFromId( 0 ) ); + DeferredUpdates::doUpdates(); } private function doPatrolledPageEdit( @@ -98,6 +102,8 @@ false, $user ); + DeferredUpdates::doUpdates(); + /** @var Revision $rev */ $rev = $status->value['revision']; $rc = $rev->getRecentChange(); @@ -588,6 +594,7 @@ $target, '20151212010101' ); + DeferredUpdates::doUpdates(); $result = $this->doListWatchlistRequest( [ 'wlprop' => 'notificationtimestamp', ] ); @@ -643,6 +650,7 @@ 'Create the page that will be deleted' ); $this->deletePage( $target, 'Important Reason' ); + DeferredUpdates::doUpdates(); } public function testLoginfoPropParameter() { @@ -920,6 +928,7 @@ $talkTarget, '20151212010101' ); + DeferredUpdates::doUpdates(); $resultUnread = $this->doListWatchlistRequest( [ 'wlprop' => 'notificationtimestamp|title', diff --git a/tests/phpunit/includes/api/ApiQueryWatchlistRawIntegrationTest.php b/tests/phpunit/includes/api/ApiQueryWatchlistRawIntegrationTest.php index 0f01664..dd3b9a2 100644 --- a/tests/phpunit/includes/api/ApiQueryWatchlistRawIntegrationTest.php +++ b/tests/phpunit/includes/api/ApiQueryWatchlistRawIntegrationTest.php @@ -84,6 +84,7 @@ $target, '20151212010101' ); + DeferredUpdates::doUpdates(); $result = $this->doListWatchlistRawRequest( [ 'wrprop' => 'changed' ] ); @@ -136,6 +137,7 @@ $subjectTarget, '20151212010101' ); + DeferredUpdates::doUpdates(); $resultChanged = $this->doListWatchlistRawRequest( [ 'wrprop' => 'changed', 'wrshow' => WatchedItemQueryService::FILTER_CHANGED ] diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index 6b299c9..88d5b78 100644 --- a/tests/phpunit/includes/api/ApiTestCase.php +++ b/tests/phpunit/includes/api/ApiTestCase.php @@ -51,7 +51,9 @@ $title = Title::newFromText( $pageName, $defaultNs ); $page = WikiPage::factory( $title ); - return $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary ); + $res = $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary ); + DeferredUpdates::doUpdates(); + return $res; } /** diff --git a/tests/phpunit/includes/deferred/LinksUpdateTest.php b/tests/phpunit/includes/deferred/LinksUpdateTest.php index 9cc3ffd..2bf8dcf 100644 --- a/tests/phpunit/includes/deferred/LinksUpdateTest.php +++ b/tests/phpunit/includes/deferred/LinksUpdateTest.php @@ -163,6 +163,8 @@ $title = Title::newFromText( 'Testing' ); $wikiPage = new WikiPage( $title ); $wikiPage->doEditContent( new WikitextContent( '[[Category:Foo]]' ), 'added category' ); + DeferredUpdates::doUpdates(); + $this->runAllRelatedJobs(); $this->assertRecentChangeByCategorization( @@ -173,6 +175,7 @@ ); $wikiPage->doEditContent( new WikitextContent( '[[Category:Bar]]' ), 'replaced category' ); + DeferredUpdates::doUpdates(); $this->runAllRelatedJobs(); $this->assertRecentChangeByCategorization( @@ -203,10 +206,12 @@ $wikiPage = new WikiPage( Title::newFromText( 'Testing' ) ); $wikiPage->doEditContent( new WikitextContent( '{{TestingTemplate}}' ), 'added template' ); + DeferredUpdates::doUpdates(); $this->runAllRelatedJobs(); $otherWikiPage = new WikiPage( Title::newFromText( 'Some_other_page' ) ); $otherWikiPage->doEditContent( new WikitextContent( '{{TestingTemplate}}' ), 'added template' ); + DeferredUpdates::doUpdates(); $this->runAllRelatedJobs(); $this->assertRecentChangeByCategorization( @@ -217,6 +222,7 @@ ); $templatePage->doEditContent( new WikitextContent( '[[Category:Baz]]' ), 'added category' ); + DeferredUpdates::doUpdates(); $this->runAllRelatedJobs(); $this->assertRecentChangeByCategorization( diff --git a/tests/phpunit/includes/jobqueue/RefreshLinksPartitionTest.php b/tests/phpunit/includes/jobqueue/RefreshLinksPartitionTest.php index 43d626d..005fbe3 100644 --- a/tests/phpunit/includes/jobqueue/RefreshLinksPartitionTest.php +++ b/tests/phpunit/includes/jobqueue/RefreshLinksPartitionTest.php @@ -26,6 +26,7 @@ $content = ContentHandler::makeContent( "[[{$title->getPrefixedText()}]]", $bpage->getTitle() ); $bpage->doEditContent( $content, "test" ); } + DeferredUpdates::doUpdates(); $title->getBacklinkCache()->clear(); $this->assertEquals( diff --git a/tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php b/tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php index 656be38..5f33f78 100644 --- a/tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php +++ b/tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php @@ -48,6 +48,8 @@ ContentHandler::makeContent( $text, $this->title ), __METHOD__ ); + DeferredUpdates::doUpdates(); + /** @var Revision $revision */ $revision = $editResult->value['revision']; $this->runJobs(); diff --git a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php index 38d63e3..2fdb32b 100644 --- a/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php @@ -14,6 +14,8 @@ protected function setUp() { parent::setUp(); + DeferredUpdates::setOpportunisticMode( true ); + $this->cache1 = new HashBagOStuff(); $this->cache2 = new HashBagOStuff(); $this->cache = new MultiWriteBagOStuff( [ diff --git a/tests/phpunit/includes/page/ArticleTablesTest.php b/tests/phpunit/includes/page/ArticleTablesTest.php index 3a3b514..0727bb8 100644 --- a/tests/phpunit/includes/page/ArticleTablesTest.php +++ b/tests/phpunit/includes/page/ArticleTablesTest.php @@ -27,6 +27,8 @@ false, $user ); + DeferredUpdates::doUpdates(); + $templates1 = $title->getTemplateLinksFrom(); $this->setUserLang( 'de' ); @@ -40,6 +42,8 @@ false, $user ); + DeferredUpdates::doUpdates(); + $templates2 = $title->getTemplateLinksFrom(); /** diff --git a/tests/phpunit/includes/page/WikiPageTest.php b/tests/phpunit/includes/page/WikiPageTest.php index 6885ca3..b8b6920 100644 --- a/tests/phpunit/includes/page/WikiPageTest.php +++ b/tests/phpunit/includes/page/WikiPageTest.php @@ -108,6 +108,7 @@ ); $page->doEditContent( $content, "[[testing]] 1" ); + DeferredUpdates::doUpdates(); $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" ); $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" ); @@ -139,6 +140,7 @@ ); $page->doEditContent( $content, "testing 2" ); + DeferredUpdates::doUpdates(); # ------------------------ $page = new WikiPage( $title ); @@ -172,6 +174,7 @@ . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat."; $page->doEdit( $text, "[[testing]] 1" ); + DeferredUpdates::doUpdates(); $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" ); $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" ); @@ -193,6 +196,7 @@ . "Stet clita kasd [[gubergren]], no sea takimata sanctus est."; $page->doEdit( $text, "testing 2" ); + DeferredUpdates::doUpdates(); # ------------------------ $page = new WikiPage( $title ); @@ -580,6 +584,7 @@ $page = $this->createPage( $title, $text, $model ); $editInfo = $page->prepareContentForEdit( $page->getContent() ); + DeferredUpdates::doUpdates(); $v = $page->isCountable(); $w = $page->isCountable( $editInfo ); -- To view, visit https://gerrit.wikimedia.org/r/330183 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I41fc8e9f548a879ead192cd013c6a7fc604113b8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Hashar <has...@free.fr> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits