Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel Testing Rspec

I am trying to run my Rspec tests in Parallel but doing so causes data conflicts i.e I have a delete_all method to give me a clean slate every tests run which causes tests running in parallel to lose the data they have created. What would be the ideal way to resolve this?

like image 449
Kevin Martin Avatar asked Jun 09 '26 13:06

Kevin Martin


1 Answers

Separate Databases.

Not sure how you are running your tests in parallel. Parallel tests should each have their own databases, otherwise, yes, you'll get massive data conflicts.

If your parallel test runners are sharing the same database and you call delete_all on one of your runners, it will cause the other runners to fail because their test databases (which are all the same) will now be empty.

Gems like parallel_tests use separate databases for each test runner by suffixing the test database name with the runner number, e.g. test_database1, test_database2, etc.

So, you should use one of these pre-built libraries that helps take care of this but if you're rolling your own, then make sure you run each runner in a separate database to avoid database conflicts.

like image 158
Joshua Pinter Avatar answered Jun 11 '26 04:06

Joshua Pinter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!