lsaffie
lsaffie

Reputation: 1814

tests getting killed in the middle of a run using parallel_tests

In an effort to get our tests to run faster, I decided to use parallel tests. https://github.com/grosser/parallel_tests

However, as usual is the case, this didn't go without issues. the tests were getting killed before finishing.

...killed.

Read on to see how I came about solving the issue.

Upvotes: 0

Views: 1083

Answers (1)

lsaffie
lsaffie

Reputation: 1814

After much troubleshooting I had to understand exactly what was happening or at least how parallel_tests was trying to run my tests.

Parallel_tests creates a database per core. So if I have 4 cores available, it would create 4 tests dbs. Then all tests are evenly distributed among the cores and executed using its own db.

To begin with, I wasn't using the right commands to setup the necessary dbs. Below is the order that worked for me.

Given your database.yml looks like this

development:
  adapter: mysql2
  encoding: utf8
  database: homestars_dev
  username: root
  password:
test: &test
  adapter: mysql2
  encoding: utf8
  database: homestars_test
  username: root
  password:

create dbs in database.yml and load the schema/structure in the dev db

rake db:setup 

create test dbs based on number of cores available

rake parallel:create

copies schema from dev db into each newly created test db

rake parallel:prepare

seed each test db

rake parallel:seed

run tests

rake parallel:rspec

With this in place, parallel_test started doing its thing correctly! However, there was still an issue that was causing tests to fail.

I had implemented GC delay using a method similar to http://ariejan.net/2011/09/24/rspec-speed-up-by-tweaking-ruby-garbage-collection/

I had it tweaked to run every 10s.

For some reason, 10s was about the time it took for each core to kill the tests! So I went and removed the lines that enable that GC hack. (by doing that, GC should still run after every test)

And for some reason, that did it! Although I still cannot understand why that is the case, I'm happy to have found a solution and understood the problem/solution better.

Take away lessons: Make sure your dbs are correctly setup before running the tests, don't use GC hacks to delay it (at least until we find the reason why it kills the processes)

Hope that helps somebody and if you have any further info, please chime in!

Upvotes: 1

Related Questions