Page MenuHomePhabricator

EntitySchema PHPUnit tests fail when FlaggedRevs is installed
Closed, ResolvedPublic

Description

Ever since we added Wikibase to EntitySchema’s CI (T333661), two PHPUnit tests have been failing (example console):

1) EntitySchema\Tests\Integration\MediaWiki\Actions\RestoreSubmitActionTest::testRestoreSubmit
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'abc'
+'def'

/workspace/src/extensions/EntitySchema/tests/phpunit/integration/MediaWiki/Actions/RestoreSubmitActionTest.php:71

2) EntitySchema\Tests\Integration\MediaWiki\Actions\RestoreViewActionTest::testRestoreView
Failed asserting that '<div class="mw-message-box-error mw-message-box">The revision you tried to restore is identical to the current revision. Nothing to do.</div><p id="mw-returnto">Return to <a href="/index.php/EntitySchema:E1234" title="EntitySchema:E1234">EntitySchema:E1234</a>.</p>\n
' contains "<ins class="diffchange diffchange-inline">abc</ins>".

/workspace/src/extensions/EntitySchema/tests/phpunit/integration/MediaWiki/Actions/RestoreViewActionTest.php:78

This is reproducible locally iff FlaggedRevisions is installed; it turns out that FlaggedRevs is a very indirect CI dependency of Wikibase (Wikibase → ArticlePlaceholder → Scribunto → SyntaxHighlight_GeSHi → VisualEditor → FlaggedRevs), and thus it’s now loaded in EntitySchema CI as well. Tracking calls to Title::loadFromRow() reveals the culprit:

(most rows removed for brevity)
/var/www/html/wiki1/includes/title/Title.php:620:
class stdClass#3344 (12) {
  public $page_title =>
  string(5) "E1234"
  public $page_latest =>
  string(1) "2"
}
/var/www/html/wiki1/includes/title/Title.php:620:
class stdClass#3349 (18) {
  public $page_title =>
  string(5) "E1234"
  public $page_latest =>
  string(1) "2"
}
/var/www/html/wiki1/includes/title/Title.php:620:
class stdClass#3349 (18) {
  public $page_title =>
  string(5) "E1234"
  public $page_latest =>
  string(1) "2"
  public $fpc_override =>
  NULL
}
/var/www/html/wiki1/includes/title/Title.php:620:
class stdClass#3299 (11) {
  public $page_title =>
  string(5) "E1234"
  public $page_latest =>
  string(1) "2"
}
/var/www/html/wiki1/includes/title/Title.php:620:
class stdClass#3820 (12) {
  public $page_title =>
  string(5) "E1234"
  public $page_latest =>
  string(1) "3"
}
/var/www/html/wiki1/includes/title/Title.php:620:
class stdClass#3349 (18) {
  public $page_title =>
  string(5) "E1234"
  public $page_latest =>
  string(1) "2"
  public $fpc_override =>
  NULL
}
/var/www/html/wiki1/includes/title/Title.php:620:
class stdClass#3349 (18) {
  public $page_title =>
  string(5) "E1234"
  public $page_latest =>
  string(1) "2"
  public $fpc_override =>
  NULL
}
/var/www/html/wiki1/includes/title/Title.php:620:
class stdClass#3924 (11) {
  public $page_title =>
  string(5) "E1234"
  public $page_latest =>
  string(1) "3"
}

Notice that there are two calls with $page_latest => 2 after the first call with $page_latest => 3, i.e., they’re resetting the latest revision ID to an outdated value; this is what causes the tests to fail, because they now load a non-latest revision as the latest revision. (It can be worked around in the tests with e.g. $page->getTitle()->resetArticleID( false ); or TestingAccessWrapper::newFromObject( $page->getTitle() )->mLatestID = false;.) And both of those calls have an $fpc_override column in the row, identifying them as coming from (or at least being influenced by) FlaggedRevs.

Ceterum censeo FlaggedRevs esse delendam.

Event Timeline

This is what FlaggedRevs thinks is appropriate to do when asked for the very latest page data, from a primary DB connection, during a transaction which hasn’t even committed yet:

class FlaggableWikiPage extends WikiPage
	protected function pageData( $dbr, $conditions, $options = [] ) {
		$cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
		$fname = __METHOD__;
		return $cache->getWithSetCallback(
			$cache->makeKey( 'flaggedrevs-pageData', $this->getNamespace(), $this->getDBkey() ),
			$cache::TTL_MINUTE,

PageUpdater::doModify()HookRunner::onRevisionFromEditComplete() [note that this is before PageUpdater calls $dbw->endAtomic( __METHOD__ );!] → FlaggedRevsHooks::maybeMakeEditReviewed()FlaggableWikiPage::loadPageData()WikiPage::pageDataFromTitle()FlaggableWikiPage::pageData() → APCu cache.

The second call mentioned earlier also comes from FlaggableWikiPage::loadPageData(), but gets there via the RecentChange::save() deferred update (which calls FlaggedRevsHooks::autoMarkPatrolled() via the onRecentChange_save() hook), which runs as part of the transaction post-commit callbacks.

Sigh, I'd be happy to review any patch/solution you have in mind.

Change 907850 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/FlaggedRevs@master] Reduce APCu cache use in FlaggableWikiPage::pageData()

https://gerrit.wikimedia.org/r/907850

Change 907803 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/EntitySchema@master] DNM: empty change to test CI

https://gerrit.wikimedia.org/r/907803

Task Review notes:

As we are going to have to depend on Wikibase in CI regardless of this task, and this dependency causes CI to break, we should regard this as an incident and therefore resolve it at this sprint.

Change 907850 merged by jenkins-bot:

[mediawiki/extensions/FlaggedRevs@master] Reduce APCu cache use in FlaggableWikiPage::pageData()

https://gerrit.wikimedia.org/r/907850

Change 907803 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/extensions/EntitySchema@master] DNM: empty change to test CI

Reason:

https://gerrit.wikimedia.org/r/907803

Change 963174 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/FlaggedRevs@REL1_40] Reduce APCu cache use in FlaggableWikiPage::pageData()

https://gerrit.wikimedia.org/r/963174

Change 963175 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/FlaggedRevs@REL1_39] Reduce APCu cache use in FlaggableWikiPage::pageData()

https://gerrit.wikimedia.org/r/963175

Change 963175 merged by jenkins-bot:

[mediawiki/extensions/FlaggedRevs@REL1_39] Reduce APCu cache use in FlaggableWikiPage::pageData()

https://gerrit.wikimedia.org/r/963175

Change 963174 merged by jenkins-bot:

[mediawiki/extensions/FlaggedRevs@REL1_40] Reduce APCu cache use in FlaggableWikiPage::pageData()

https://gerrit.wikimedia.org/r/963174