Page MenuHomePhabricator

Fix tests misusing $wgCommandLineMode to delay DeferredUpdates execution
Closed, ResolvedPublic

Description

In web requests, DeferredUpdates are executed at the end of the requests, while in maintenance scripts, they are executed immediately – this is implemented by checking $wgCommandLineMode (https://gerrit.wikimedia.org/g/mediawiki/core/+/6c07e2acf1e6e39831c2b4cab8ab62feb4096277/includes/deferred/DeferredUpdatesScopeMediaWikiStack.php#55).

$wgCommandLineMode is also true when running tests, and we have a number of test cases that override it to false to prevent DeferredUpdates from executing immediately, because they interfere with the test setup in some way.

Since I'd like to get rid of $wgCommandLineMode in T313841, they need to be updated to use something else. I'm hopeful that DeferredUpdates::preventOpportunisticUpdates() will work, it's a relatively new thing (84f0876b8302cd7d7ec727b2ed5daa49b6bddcc5) with a similar effect (not exactly the same, but hopefully close enough).

Event Timeline

Change 982381 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/CirrusSearch@master] Use preventOpportunisticUpdates() instead of $wgCommandLineMode hacks

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

Change 982381 merged by jenkins-bot:

[mediawiki/extensions/CirrusSearch@master] Use preventOpportunisticUpdates() instead of $wgCommandLineMode hacks

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

Change 982398 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@master] Use preventOpportunisticUpdates() instead of $wgCommandLineMode hacks

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

Change 982398 merged by jenkins-bot:

[mediawiki/core@master] tests: Change $wgCommandLineMode hacks to preventOpportunisticUpdates()

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

Codesearch: https://codesearch.wmcloud.org/search/?q=CommandLineMode&files=tests

There are more results, but it turns out the rest of them are different problems. I was hoping to find more of these, since they're easy to fix, but the occurrences in GrowthExperiments, Phonos and other tests in core override 'CommandLineMode' for different reasons.

There's one result in a third-party extension, and although that's usually out of scope, I was so disappointed, that I wrote a patch for it too: https://github.com/edwardspec/mediawiki-moderation/pull/82