Commit graph

15 commits

Author SHA1 Message Date
Func
4d1da6f7f8 phpunit: Update @covers annotations for namespaced classes
We renamed many classes to be namespaced, but the `@covers` and
`@coversDefaultClass` annotations weren't updated properly.

PHPUnit didn't support short cover annotations with `use` statements,
these didn't trigger any errors yet, because they are class alias.

This patch is populated by a modified version of PhpunitAnnotationsSniff.

Change-Id: I6c602290a30099239b17d2dc0d67b1488b4eaeeb
2023-05-27 17:43:12 +08:00
Amir Sarabadani
e182010622 Reorg: Move SiteStats*.php to SiteStats/
It's going to be a bit small and narrow but it's better than sitting in
the root of includes/ plus I hope we can hollow out SiteStatsUpdate
class into the third one and or move this under a better directory in
the future.

Bug: T321882
Change-Id: Ia503b53b31ca00600f8c18b61a2652c3e146494e
2023-04-27 01:16:29 +02:00
Umherirrender
2b44fbe3eb SiteStats: Remove unneeded SiteStats::salvageIncorrectRow
The function SiteStats::salvageIncorrectRow is a noop,
the variable $map is not returned, instead the unmodified $row is
returned, function added in 6535091

self::doLoadFromDB on second attempt after the initialize (via
doPlaceholderInit or doAllAndCommit) returns a valid row, making this
extra check no longer needed (possible since 27c76fa).

Fix doLoadFromDB on first attempt for empty table, broken since 5156ae0

Change-Id: Iec2b4bbdb2ca546eb377a6d12106d62b5219886f
2023-02-13 21:23:40 +01:00
Derick Alangi
83cdb69ed2 Avoid deprecated usage of Job::factory()
Change-Id: Ia2b8b71159ed8d387ae31f921ddcfd0d9136118c
2023-01-25 13:25:40 +02:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Daimona Eaytoy
2b37cfaf18 build: Bump mediawiki-codesniffer to 31.0.0
Done with `composer fix` and suppressing the rest (i.e. sniffs for
global variables, which for core should be suppressed anyway).

Additionally, add `-p` to `phpcbf`, as otherwise it just seems stuck.

Change-Id: Ide8d6cdd083655891b6d654e78440fbda81ab2bc
2020-05-30 14:56:28 +00:00
Umherirrender
5bd311b1a2 Add public as visibility in tests folder
Add public, protected or private to function missing a visibility
Enable the tests folder for the phpcs sniff

Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
2019-10-10 21:55:37 +02:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
assertSame() is guaranteed to not do any type conversion. This can be
critical when acciden tially comparing, for example, 0 to 0.0.

Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
2019-09-19 15:35:23 +00:00
Aaron Schulz
fc5d51f129 jobqueue: add GenericParameterJob and RunnableJob interface
Simplify the code of jobs that do not care about titles and removes
the direct Title dependency from JobQueue. Remove getTitle() from
IJobSpecification itself. Move all the Job::factory calls into a
single JobQueue::factoryJob() method.

Depends-on: Iee78f4baeca0c0b4d6db073f2fbcc56855114ab0
Change-Id: I9c9d0726d4066bb0aa937665847ad6042ade13ec
2019-04-08 11:05:23 -07:00
Timo Tijhof
45660456cf 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
2018-04-24 00:46:19 +01:00
Eddie Greiner-Petter
edba39ab60 Be more db-friendly when purging expired userrights
Each expired row has to be fetched from the user_groups table, deleted
from that table and added to the user_former_groups table.  Per Jaimes
request, let's not do this for all rows at once but for smaller chunks
and wait for replication to catch up after each chunk has been
processed. In addition the function to purge the expired rows now sets a
lock so that there won't be multiple concurrent runs.

Also, cleaning this table up isn't urgent and thus should be done in a
job and not a deferred update, so let's move it there.

Bug: T176754
Change-Id: I671d4b9d09677a2f474477ba7fea33a44d6318aa
2018-02-14 09:02:33 +00:00
Brad Jorsch
d0b093d4bd Improve flaky SiteStatsTest
SiteStatsTest::testJobsCountGetCached() is somewhat flaky in that if it
runs after a test that adds a page (thereby producing htmlCacheUpdate
and recentChangesUpdate jobs) but doesn't have the CI framework reset
the `page` tables (which has the side effect of clearing all such jobs),
it will fail.

This change manually clears those jobs so it doesn't depend on test
ordering.

Change-Id: I1277e633c81b29bda7564fa12d23f13ded7298c7
2017-09-12 11:48:41 -04:00
Antoine Musso
29aaac5c63 Add WAN Cache to SiteStats::jobs
The method hits the jobrunner backend to find out how many jobs are
enqueued in each of the JobQueue.  It is publicly available via the
MediaWiki API request:
    /w/api.php?action=query&meta=siteinfo&siprop=statistics

That is often used by bots when querying recent changes among other and
with fast bot cause useless queries toward the jobrunner backend.

Wrap SiteStats::jobs() with a WAN cache under key SiteStats:jobscount.
Drop SiteStats::$jobs private variable that was used for in process
cache. The WAN Cache does it for us via 'pcTTL'.

That is similar to SiteStats::numberingroup().
Set TTL to one minute, which should still give fresh enough results for
public uses.

Cover that behavior with a test.

When writing tests I noticed MediaWikiTestCase generates a few jobs due
to the creation of the UTPage page:

* HTMLCacheUpdateJob to refresh backlinks (eg: history)
* RecentChangesUpdateJob which happens randomly

Pass EDIT_SUPPRESS_RC to doEditContent to prevent the first and blindly
delete entries in the recentChangesUpdate jobqueue for the second.

Change-Id: I95a272d0691d779bfee9e7a671cbab66a113dfa1
2017-07-25 18:17:34 +00:00