Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Mutant's phpunit.xml, set executionOrder="default" to prevent random ordering of the tests since we need them to be sorted (fastest - first) #1547

Merged
merged 1 commit into from Aug 7, 2021

Conversation

maks-rafalko
Copy link
Member

@maks-rafalko maks-rafalko commented Aug 7, 2021

During the work on #1519, found that we have a critical bug. We always said we run the tests from fastest to slowest, hoping that the fastest tests fail first. It's true, unless the original phpunit.xml has an executionOrder=random attribute set (closest example - Infection's test suite itself).


When Infection builds Mutant's phpunit.xml file, we add <file> tags, sorted by tests execution time, so that the fastest tests runs first.

But when the original phpunit.xml contains executionOrder="random", it was inherited to Mutant's phpunit.xml and broke the order, running the tests in a random order each time infection was executed.

This also explains why I got different execution time of Infection for the project with slow functional tests (there is the same issue for unit tests, but they are fast enough so this issue is not visible).

When Mutant is covered by 1000 functional tests, and tests are executed by random, it can be killed by the first test in run #1 and can be killed by 1000-th test in run #2, if the killing test is executed the last.

With this update, all the tests will be executed in the same orders (fastest - first) in all the infection runs.

For more clarity, this is what happens in master right now with executing the same command 2 times:

'phpunit' '--configuration' 'infection/phpunitConfiguration.96749d7e4a15eec4f82a2413a56b5fba.infection.xml

#1 run:

PHPUnit 9.5.7 by Sebastian Bergmann and contributors.

Random Seed:   1628355728

Testing 
.............................................................   61 / 1404 (  4%)
.............................................................  122 / 1404 (  8%)
.............................................................  183 / 1404 ( 13%)
.............................................................  244 / 1404 ( 17%)
.............................................................  305 / 1404 ( 21%)
.............................................................  366 / 1404 ( 26%)
.............................................................  427 / 1404 ( 30%)
.............................................................  488 / 1404 ( 34%)
E

Time: 01:05.354, Memory: 459.00 MB

There was 1 error:

#2 run:

PHPUnit 9.5.7 by Sebastian Bergmann and contributors.

Random Seed:   1628355731

Testing 
.............................................................   61 / 1404 (  4%)
.............................................................  122 / 1404 (  8%)
.............................................................  183 / 1404 ( 13%)
.............................................................  244 / 1404 ( 17%)
..E

Time: 00:49.420, Memory: 349.00 MB

There was 1 error:

^ you can see that tests were executed in a random order, and the killing test was 499th in the #1 run, and 245th in the #2 run

…andom ordering of the tests since we need them to be sorted (fastest - first)

When Infection build Mutant's `phpunit.xml` file, we add `<file>` tags, sorted by tests execution time, so that the fastest tests runs first.

But when the original `phpunit.xml` contains `executionOrder="default"`, it was inherited to Mutant's `phpunit.xml` and broke the order, running the tests in a random order each time `infection` was executed.

This also explains why I got different execution time of Infection for the project with *functional* tests.

When Mutant is covered by 1000 functional tests, and tests are executed by random, it can be killed by the first test in run #1 and can be killed by 1000-th test in run #2, if the killing test is executed the last.

With this update, all the tests will be executed in the same orders (fastest - first) in all the infection runs.
Copy link
Member

@sidz sidz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@maks-rafalko maks-rafalko merged commit 5c6b61f into master Aug 7, 2021
@maks-rafalko maks-rafalko deleted the bugfix/default-order branch August 7, 2021 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants