Page MenuHomePhabricator

Un-forbid PHPUnit annotations for process isolation in our PHPCS config
Open, Needs TriagePublic

Description

Our PHPCS configuration forbids PHPUnit annotations related to process isolation, and specifically @preserveGlobalState, @runTestsInSeparateProcesses, and @runInSeparateProcess. However, process isolation is necessary to test code that triggers HTTP headers without resorting to poorly-supported PHPUnit config options (T420009). The patch that forbade these annotations did not provide a rationale for doing so, except I guess for the fact that these annotations are "unusual" in that we basically don't use them anywhere. Now I am proposing that we un-forbid them, so we can use them to fix those tests.

I also found two mentions in phabricator for runInSeparateProcess:

Event Timeline

If they're truly only going to be used in two or three tests, our policy is that they should remain banned and have an inline disable with an explanatory comment. Is that not appropriate here?

If they're truly only going to be used in two or three tests, our policy is that they should remain banned and have an inline disable with an explanatory comment. Is that not appropriate here?

Yeah, that would work too, especially now that I took the approach of wrapping the header function for all callers and disabling it in tests, so that there's really just a couple tests that need to exercise headers.

I guess my point here was that it's not clear why the annotations are forbidden in the first place, as it seemed more of a case of "we typically don't use them, so we should never use them", which lacks a real rationale. OTOH, process isolation does make tests much slower and should be used sparingly, so I'm also fine with keeping it disabled. Nonetheless, I do think we should document why that is the case.

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

[mediawiki/tools/codesniffer@master] Document why PHPUnit process isolation is forbidden and support its tags

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

FWIW:

T319459: Re-work Minify's testRunJsFile test to not use forbidden @runInSeparateProcess which breaks CI publishing suggests that arguments for the coverage driver aren't passed to isolated tests. I have just tried this for a random test in MW core, and I still get coverage data for isolated tests. So, assuming that the issue still exists, we can re-verify it in CI and probably find a fix directly there

It was fixed upstream, but only for driver-specific arguments such as pcov.enabled=1. It still doesn't work when the extension is enabled via CLI flags, for which I just filed https://github.com/sebastianbergmann/phpunit/issues/7053. Even if that bug is fixed, it won't be backported to the ancient PHPUnit versions we are using, so we'd need a workaround in CI for the time being (enabling pcov via ini before running tests should do).