Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Is hydra expected to provide any benefit without using RSpec or Factory Girl? #33

Open
briantobin opened this issue Jan 22, 2011 · 4 comments

Comments

@briantobin
Copy link

Forgive the dumb question but I haven't been able to find an answer online. Using traditional fixtures and Test::Unit I can run unit tests in 1 minute 16 seconds:

time rake test:units
235 tests, 3813 assertions, 0 failures, 0 errors

real    1m16.273s
user    0m40.823s
sys 0m2.352s

I installed the hydra gem and added the following to my Rakefile:

Hydra::TestTask.new('hydra') do |t|
  t.add_files 'test/unit/**/*_test.rb'
end

My config/hydra.yml looks like this:

workers:
    - type: local
      runners: 2

Running my unit tests inside hydra results in a slowdown:

time RAILS_ENV=test rake hydra
(in /home/brian/co/manage)
Hydra Testing [##############################>] 87/87

real    2m5.797s
user    0m0.384s
sys 0m0.208s

I'm wondering if this is because I'm not using RSpec or Factory Girl or Cucumber or anything else that the cool kids are using these days. The database is Postgres and I have transaction fixtures and concurrent connections enabled. Any help would be appreciated. Thanks!

Brian

@ngauthier
Copy link
Owner

Actually, I prefer plain old test unit, and it should give you a speedup! I don't usually use fixtures, but if the tests pass then you're fine.

It's probably database deadlocks that are slowing you down. Try running the hydra task with verbose mode enabled. Paste that in here and I'll take a look.

https://github.com/ngauthier/hydra/wiki/Frequently-Asked-Questions

-Nick

@briantobin
Copy link
Author

Hi Nick. Thanks for your reply. As you predicted, it is a problem with deadlock. An example from running in verbose mode:

1295901694.62493 WORKER|    #<Hydra::Messages::Runner::Results:0xb77091c8 @file = "test/unit/traffic_shaper_class_test.rb", @output="Error:\ntest_fixtures(TrafficShaperClassTest):\nActiveRecord::StatementInvalid: PGError: ERROR:  deadlock detected\nDETAIL:  Process 24254 waits for RowExclusiveLock on relation 51642347 of database 50430982; blocked by process 24255.\nProcess 24255 waits for AccessExclusiveLock on relation 50431235 of database 50430982; blocked by process 24254.\n: DELETE FROM \"traffic_shaper_classes\"\n    config/initializers/meraki.rb:875:in `silence'\nError:\ntest_truth(TrafficShaperClassTest):\nActiveRecord::StatementInvalid: PGError: ERROR:  deadlock detected\nDETAIL:  Process 24254 waits for RowExclusiveLock on relation 51642347 of database 50430982; blocked by process 24255.\nProcess 24255 waits for AccessExclusiveLock on relation 50431235 of database 50430982; blocked by process 24254.\n: DELETE FROM \"traffic_shaper_classes\"\n    config/initializers/meraki.rb:875:in `silence'">
1295901694.62533 MASTER| got message: #<Hydra::Messages::Worker::Results:0xb770f028>
1295901694.62538 MASTER| Deadlock detected running [test/unit/traffic_shaper_class_test.rb]. Will retry at the end

I added the call to use_concurrent_connections but haven't seen any changes. To confirm what I read in the FAQ, I appended this to test/test_helper.rb:

# raise 'blah'
ActiveRecord::TestCase.use_concurrent_connections

When the raise is uncommented all the tests fail, so I'm confident that my code is being reached. Anything else I should try?

@ngauthier
Copy link
Owner

as of right now hydra doesn't support using multiple databases, so I think you're stuck :-(

You can try setting "autosort" to false in the task, and ordering your tests as best you can to minimize deadlock. You can also move the "naughty" tests to a separate task, and set "serial" to true in that task to force them to run by themselves.

Sorry.

@briantobin
Copy link
Author

Thanks Nick. I dug a little deeper using test_benchmark (https://github.com/timocratic/test_benchmark) and discovered that some of the biggest offenders don't touch the DB. I'll try grouping my tests into those which can be run in parallel and those that cannot.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants