Page MenuHomePhabricator

[REPO][CLIENT][SW] Create a `composer phpunit:prepare-parallel-test-suites` command to split suite into smaller groups
Closed, ResolvedPublic

Description

As part of a staged implementation of native PHP parallel PHPUnit testing, and following on from T361190, create a composer command to generate split groups of tests from a specified (or the default) test suite.

Splitting the suite into smaller groups will allow us to run those groups locally or from Quibble by passing the --testsuite argument to PHPUnit.

When this is implemented as a composer task in Mediawiki, we will be able to remove the Python splitting implementation introduced into Quibble in T361190.

Acceptance Criteria

  • Running composer phpunit:prepare-parallel-test-suites generates a phpunit.xml containing split groups of tests
  • Executing each of the newly generated test suites individually runs the same set of tests that running the original suite does.

Related Objects

Event Timeline

Change #1038280 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/core@master] [WIP] Add PHPUnit splitting

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

Change #1038609 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/core@master] [WIP] Add `phpunit:parallel:extensions` composer command

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

Change #1039669 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[integration/quibble@master] Add parallel execution for PHPUnit extensions suite

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

Change #1039675 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[integration/quibble@master] [DNM] Enable parallel runs by setting QUIBBLE_PHPUNIT_PARALLEL

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

By way of validation, I did a couple of test runs comparing the .phpunit.results.cache files between the linear and parallel execution and found no difference in the tests executed:

Extensions Databaseless

Linear

$ composer phpunit:entrypoint -- --testsuite extensions --exclude-group Broken,ParserFuzz,Stub,Standalone,Database
...
Tests: 30413, Assertions: 86903, Skipped: 163.

$ cat phpunit-result-cache-extensions-databaseless-linear-20240627 | jq .times | grep ':' | sed -e 's/^\(.*\): .*$/\1/' | sort | uniq | wc -l
30390

Parallel

$ composer run phpunit:prepare-parallel:extensions
$ composer run phpunit:parallel:databaseless
$ cat phpunit-result-cache-extensions-databaseless-parallel-* | jq .times | grep ':' | sed -e 's/^\(.*\): .*$/\1/' | sort | uniq | wc -l
30403

Note that here 30403 is slightly higher than 30390. I expect this is because we end up repeating some tests in the split mode. The comparison below checks that the test coverage complete - that linear only runs the tests that parallel runs and vice versa - even if some tests are repeated.

Compare

$ cat phpunit-result-cache-extensions-databaseless-parallel-*-20240627 | jq .times | grep ':' | sed -e 's/^\(.*\): .*$/\1/' | sort | uniq > /tmp/parallel
$ cat phpunit-result-cache-extensions-databaseless-linear-20240627 | jq .times | grep ':' | sed -e 's/^\(.*\): .*$/\1/' | sort | uniq > /tmp/linear
$ diff /tmp/linear /tmp/parallel

Extensions Database

Linear

$ composer run --timeout=0 phpunit:entrypoint -- --testsuite extensions --exclude-group Broken,ParserFuzz,Stub,Standalone --group Database

ERRORS!
Tests: 16327, Assertions: 70141, Errors: 147, Failures: 14, Skipped: 174.

$ cat phpunit-result-cache-extensions-database-linear-20240627  | jq .times | grep ':' | sed -e 's/^\(.*\): .*$/\1/' | sort | uniq | wc -l
15102

This particular run had some failures because my environment wasn't set up correctly for the tests to pass, but the comparison should still be valid.

Parallel

$ composer run phpunit:prepare-parallel:extensions
$ composer run phpunit:parallel:database
$ cat phpunit-result-cache-extensions-database-parallel-*-20240627 | jq .times | grep ':' | cut -d':' -f -3 | sort | uniq | wc -l
15102

Compare

$ cat phpunit-result-cache-extensions-database-parallel-*-20240627 | jq .times | grep ':' | sed -e 's/^\(.*\): .*$/\1/' | sort | uniq > /tmp/parallel
$ cat phpunit-result-cache-extensions-database-linear-20240627 | jq .times | grep ':' | sed -e 's/^\(.*\): .*$/\1/' | sort | uniq > /tmp/linear
$ diff /tmp/linear /tmp/parallel

But I would welcome other people doing similar tests / evaluations, or also alternative approaches.

Change #1039675 abandoned by Arthur taylor:

[integration/quibble@master] [DNM] Enable parallel runs by setting QUIBBLE_PHPUNIT_PARALLEL

Reason:

No longer needed - this is enabled for the relevant CI jobs anyway

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

Change #1038280 merged by jenkins-bot:

[mediawiki/core@master] Add `phpunit:prepare-parallel:extensions` command

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

Change #1038609 merged by jenkins-bot:

[mediawiki/core@master] Add `phpunit:parallel:extensions` composer command

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

Change #1039669 merged by jenkins-bot:

[integration/quibble@master] Add support for core's composer `phpunit:...parallel:...` commands

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

Change #1073438 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[integration/quibble@master] release: Quibble 1.10.0

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

Change #1073476 had a related patch set uploaded (by Hashar; author: Hashar):

[integration/config@master] dockerfiles: update Quibble to 1.10.0

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

Change #1073438 merged by jenkins-bot:

[integration/quibble@master] release: Quibble 1.10.0

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

Change #1073476 merged by jenkins-bot:

[integration/config@master] dockerfiles: update Quibble to 1.10.0

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

Change #1073542 had a related patch set uploaded (by Hashar; author: Hashar):

[integration/config@master] jjb: switch jobs to Quibble 1.10.0

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

Change #1073542 merged by jenkins-bot:

[integration/config@master] jjb: switch jobs to Quibble 1.10.0

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

Not from my side. This is in Tech Review Verification on our board, but that column is not very active. If you're satisfied that the acceptance criteria are met, please feel free to close this.

(restoring assignee after column trigger unintentionally cleared it)