How to use multiple mysql container databases to run php unit tests in parallel

Drew Gallagher February 7, 2023

My team is using Laravel tested with phpunit.

 

We want to run our tests in parallel however when using paratest it tries to connect to multiple databases, and the databases need to exist before running it. 

 

For example if my database name is nova, it will try to connect to nova_1, nova_2...nova_N, for each process in parallel. 

 

I could write a script to connect to msyql and create those databases, but I thought it might be easier to define multiple containers with mysql databases for each up to N processes. 

 

Is there a way to to use more than one mysql container database so I can achieve this?

 

https://laravel.com/docs/9.x/testing#running-tests-in-parallel

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2023

Hi Drew,

I don't think this is possible with service containers, as they don't support port mapping and each service will use its default port. If you define multiple mysql services, all of them will try to use port 3306 and the build will fail.

However, you can spin up multiple database containers with Docker Compose instead and use a different port for each container, or you could use one mysql service container and create the different databases in that container.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events