Page MenuHomePhabricator

Make MediaWikiIntegrationTestCase::getExistingTestPage() default to random title
Closed, ResolvedPublic

Description

Currently, MediaWikiIntegrationTestCase::getExistingTestPage() defaults to the constant title UTPage. This means that tests which don’t properly clear all database tables can have state related to this UTPage page leaking between them, as several tests will all target the same page; such issues can be quite tricky to debug (see T340004 and T341210 for an example where this happened in FlaggedRevs).

To avoid this, I think getExistingTestPage() should choose a random title (it could still start with UTPage as a prefix), like e.g. getNonexistingTestPage() already does ('UTPage-' . rand( 0, 100000 )).

Event Timeline

A possible counterargument to this is that for correctly implemented tests, this shouldn’t be a problem: if a test is broken, it means the test is failing to clear some database table (if I understand correctly). You could argue that it’s better to let such tests fail so that they can be fixed.

But given how confusing the test failure in T341210 was, and how I was totally unable to spot the real reason, I’m not very convinced that the current behavior really helps with identifying such tests.

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

[mediawiki/core@master] tests: Make getExistingTestPage default to random title

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

Note this was not really the root cause for the problem in the linked tickets. That was not because of the title but because of a revision id (e.g. 4) that got "reused" in unexpected ways.

I'm a little worried that a random title might make our test suite slower. Most tests probably don't care that much if a page existed before or not. If they do they should say so. Maybe it's a naming issue? Can we come up with something that's better than getExistingTestPage and maybe makes the difference between "always the same page" vs. "you have to specify a page name" more visible?

Note this was not really the root cause for the problem in the linked tickets. That was not because of the title but because of a revision id (e.g. 4) that got "reused" in unexpected ways.

Ah okay, I missed that part.

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

[mediawiki/core@master] Use explicit title in RevertedTagUpdateIntegrationTest

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

Change 936282 merged by jenkins-bot:

[mediawiki/core@master] Use explicit title in RevertedTagUpdateIntegrationTest

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

I'm not sure if I like the original proposal as written here. The reason why getExistingTestPage defaults to a fixed title is to avoid unnecessarily creating a new page unless there's a good reason to. For every test in the Database group, the page UTPage is always created by the test framework, meaning any database test that needs an existing page has it for free without doing anything special. Now, we could argue whether creating a page for every test class is a good idea; maybe not. But as long as we do that, I think the title used by getExistingTestPage should match the one used in addCoreDBData.

That said, making it something other than "UTPage", and possibly randomized, would help with the tests that use this hardcoded value (search), which might be very surprising if you don't know what UTPage actually is.

Also, IIUC, the root cause of the two failures linked in the task description was a test forgetting to set tablesUsed. I've proposed an alternative solution to that in T342301.

Change 947378 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/core@master] phpunit: Randomize and improve default test page names

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

Change 947378 merged by jenkins-bot:

[mediawiki/core@master] phpunit: Randomize and improve default test page names

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

Daimona removed a project: Patch-For-Review.

Test page names now default to the name of the caller method, and also have a random component for good measure.

Change 949192 had a related patch set uploaded (by Jforrester; author: Jforrester):

[mediawiki/core@master] Follow-Up 77d4c2c: Make getExistingTestPage() check content type first

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

Change 949401 had a related patch set uploaded (by Jforrester; author: Jforrester):

[mediawiki/core@master] Follow-Up 77d4c2c: Make getExistingTestPage() not throw if it didn't work out for now

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

Change 949401 abandoned by Jforrester:

[mediawiki/core@master] Follow-Up 77d4c2c: Make getExistingTestPage() not throw if it didn't work out for now

Reason:

We're going with Ia381fb729e1da6af90b8c3165fa072dfe5675b17 instead.

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

Change 949192 merged by jenkins-bot:

[mediawiki/core@master] Follow-Up 77d4c2c: Make getExistingTestPage() check content type first

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

Change 936275 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/core@master] tests: Make getExistingTestPage default to random title

Reason:

done in I9c2dc1cf1f

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