Skip to content

Instantly share code, notes, and snippets.

@dbaltas
Last active February 8, 2019 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbaltas/4672866 to your computer and use it in GitHub Desktop.
Save dbaltas/4672866 to your computer and use it in GitHub Desktop.
Running Paratest on different database instances
Hi Brian, @brianium
Congratulations on Paratest.
It is a very well written project.
We (as tripsta organization) want to run our test suite in parallel.
Our application is on Zend Framework 1.12, php 5.4, phpunit 3.5.15 and mysql 5.5.
Our test suite has 13000 unit tests and is taking around 22 minutes to run on our testing environment.
Most of the tests have (unfortunately) heavy database access.
The problem is that running phpunit on multiple processes accessing a single same database
generates many deadlocks.
We want to have paratest processes run on different test databases to avoid deadlocks.
This approach would require each child process to connect a separate database.
A suggested solution is:
The main process has a pool of tokens.
When it starts a new child process it passes a token to it.
When it runs out of available tokens, no new process can be created.
When a process ends, the token that was used by this process becomes available.
Any ideas/concerns on this?
In any event we will be working on this implementation in the next couple of days so maybe
you can give it a review or follow up after we are done
on our paratest fork, https://github.com/tripsta/paratest.
In general we are willing to collaborate/contribute on the project.
Keep on the good work!
@brianium
Copy link

This seems like an interesting concept. I am curious on how each process would communicate it's given database information to phpunit. I have a couple of ideas off the top of my head, but not sure if they are viable.

I am eager to see your implementation, and of course collaborators and contributors are always welcome.

Thanks for taking an interest!

@dbaltas
Copy link
Author

dbaltas commented Jan 31, 2013

Hey Brian,

Our test suite is running with Paratest on dev environment! We decreased times from 22' to 5'50'' on my machine and from 12' to 3'10'' on a dev machine with SSD drive.

Thank you so much!

Regarding the implementation you can take a look at tripsta/paratest@faf6317.

The main process starts phpunit with the environment variable TEST_TOKEN.
For example with 3 processes
TEST_TOKEN=1 phpunit file1
TEST_TOKEN=2 phpunit file2
TEST_TOKEN=3 phpunit file3
...etc
The tokens are as many as the processes specified on the paratest binary with the -p option.
When a process ends it releases the token and a new process can use it.
TEST_TOKEN=1 phpunit file

On the database side we need testdb1, testdb2, testdb3 which are clones of the testdb.
The number of processes/databases is specified in our database configuration file.
A script creates these databases and runs migrations (schema updates on them)
The creation of these databases only needs to happen once.
On consecutive runs we only ensure that their schema is up to date.

On the application side, the TEST_TOKEN environment variable is used to generate the database name to which the phpunit process will connect to.

I'll try to document the process better at a later stage.

I hope you like it!

@hungvietdo
Copy link

Hi Dbaltas,

I am in the same situation where I want to run paratest using multiple databases (to reduce deadlock and mock data setup conflict).

Have you already had resolution regarding to this challenge?

Thank you,
Hung

@kocoten1992
Copy link

@hungvietdo I've similar requirement as yours, (each test runing within it's own database), you might want this https://github.com/liuggio/fastest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment