3

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?

4
  • find a way so as not to need delete_all. Why do you think you need it? Commented Mar 10, 2015 at 4:12
  • When using a page.find if I haven't deleted the element from the previous test run, it will result in ambiguous result. @TarynEast Commented Mar 10, 2015 at 17:43
  • You shouldn't need to delete things from a previous test run... the test-database is set up in such a way that unless you've jiggered with the setting - it should delete itself after every test run. Commented Mar 10, 2015 at 22:03
  • 2
    How are you running your tests in parallel. Parallel tests should have their own database otherwise, yes, you'll get massive data conflict. Gems like github.com/grosser/parallel_tests do exactly that so make sure you're doing that or use one of the pre-built gems out there. Commented Aug 2, 2018 at 23:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I wonder why the downvotes? This clearly sounds like the issue to me, even 1.5 years later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.