Add INFECTION
and TEST_TOKEN
environment variables for each Mutant process
#1504
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
INFECTION
andTEST_TOKEN
environment variables for each Mutant process to make it possible to run functional tests for different databases.Background:
We have a lot of functional tests that do real SQL queries to MySQL and decided to run tests in parallel. To achieve it, we integrated Paratest library.
Parallel processes can not write to the same database, because tests start to conflict with each other. To fix this issue, Paratest provides
TEST_TOKEN=<int>
environment variable for each process that can be used to set up different connections to the databases.So if you have 3 parallel processes, these processes will use
db_1
,db_2
,db_3
correspondingly.Infection's issue with functional tests
The same goes for Infection. As soon as we start using more than 1 thread, our
ParallelProcessRunner
runs processes in parallel, and withoutTEST_TOKEN
being passed, all those processes use the same database, which fails the test, making the majority of the Mutants killed.This PR adds
TEST_TOKEN=<int>
env variable for each "mutant process".Note: we can't use round-robin for thread indexes, because different processes take different amount of time. Consider the following example:
Imagine -we run Infection with 3 threads:
infection -j3
, and we have 4 mutations, so we need to run 4 processes when 3 of them can be in parallelIn this example, as soon as Process 3 finishes its work, we can run Process 4. It will mean that at the same time we will have exactly 3 parallel processes
But, since Process 1 takes too much time, round-robin algorithm gives
TEST_TOKEN
values of 1 for Process 4. And we have a situation where both processes Process 1 and Process 4 work with the same database at the same time.To avoid such an issue, in this PR
TEST_TOKEN
gets the first available (free) index that is not used at this point of time by any other processes. For example above, as soon as Process 3 finishes its job, Process 4 will getTEST_TOKEN=3
, because values 1 and 2 are still busy.INFECTION
env variableIn our application, we have a custom
bootstrup
for PHPUnit, where we removevar/cache
folderSince Infection runs PHPUnit in separate processes, this bootstrap file gets called for each Mutant, again breaking the whole process, because while Process 1 can work, Process 3 removes its cache.
So, we need to understand when PHPUnit process is executed from Infection, and skip such removing:
This PR:
INFECTION
andTEST_TOKEN
environment variables site#214