phpunit: Clear job queues in MediaWikiTestCase::setUp()
This should fix the flaky unit test 'SiteStatsTest::testJobsCountGetCached',
which fails locally as follows, when run in isolation.
> 1) SiteStatsTest::testJobsCountGetCached
> A single job enqueued bumps jobscount stat to 1
> Failed asserting that 2 matches expected 1.
>
> /var/www/mediawiki/tests/phpunit/includes/SiteStatsTest.php:22
> /var/www/mediawiki/tests/phpunit/MediaWikiTestCase.php:421
> /var/www/mediawiki/maintenance/doMaintenance.php:94
Instrumenting JobQueueMemory::doBatchPush reveals the following
jobs to have been queued.
- MediaWikiTestCase->run/->addCoreDBData/::getTestSysop/..
../User->addGroup/UserGroupMembership->insert/..
> UserGroupExpiryJob (2)
- MediaWikiTestCase->run/->addCoreDBData/WikiPage->doEditContent/..
../WikiPage->{closure}/WikiPage->doEditUpdates/JobQueueGroup->lazyPush/..
> CategoryMembershipChangeJob
> HTMLCacheUpdateJob (2)
Fix this by adding clearing of job queues to doLightweightServiceReset()
in MediaWikiTestCase.
Also:
- Move the call to doLightweightServiceReset() from run() to setUp(),
where it is easier to understand in context. It still runs at the same
logical point because PHPUnit calls setUp() right before run().
- Remove redundant reset for WANObjectCache->clearProcessCache that
was both in setUp() and in doLightweightServiceReset().
- Simplify SiteStatsTest by removing the hardcoded delete() calls.
An alternative fix for the flaky unit test would've been to add
a delete() call to categoryMembershipChange, but rather than hardcoding
all possible jobs that TestCase or another test could make, it's easier
to just reset/delete them all between tests.
- Simplify SiteStatsTest by using the $cache reference directly instead
of roundtripping through MediaWikiServices. If for some reason
setService() didn't work, the test will fail either way because it must
match the one used by JobQueueGroup (TODO: Use injection!), and besides
the setService() method already has its own unit test.
Change-Id: Ia4b7871221c76c65eacf31915b515705a36940d5