"Grease Your Suite: Tips and Tricks for Faster Testing" - Nick Gauthier
Nick uses, Rails, Shoulda, Factory Girl, and Paperclip. He favors Factory Girl over fixtures, as do I. Shoulda is interesting because it can be integrated with Test::Unit but still give it a BDD feel. I've used it a bunch of times but the jury is still out for me.
In his "vanilla" test suite, the one with standard unit and functional tests (and probably other), takes 13 minutes, 15 seconds.
Implementing Shoulda with nested contexts took the test time down to about 5 minutes.
Using Paperclip saves time during functional testing. By using Paperclip to return negligibly sized images during
parallel_tests, specjour, deep-test and tickle are tools to fork your testing process across multiple cores. According to Nick, these are good tools but they don't do the "balancing" across the cores very well. parallel_tests is for Test::Unit. It requires more setup in that you have to have multiple test databases running.
But Nick recommends hyrdra. It will run with Test::Unit (still tops in my mind) and doesn't require multiple db setup. On top of that, it has "smarter" balancing across multiple cores. It will also run with cucumber.
Some background on environment loading. Test::Unit will actually load the env 4 times. Cucumber does 2 and RSpec tests just does it once. Hydra also only boots the env once even for multiple test frameworks.
Hydra brought the testing time back to 1 minute, 26 seconds.
The default behavior for filesystem mounting on most 'nix systems is journalling enabled. This means that all ata is committed into the journal prior to being written into the main filesystem. Another option is journal_data_writeback. This means that data may be written into the main filesystem after its metadata has been commited to the journal. This will increase speed, but at the cost of total safety of your metadata. You don't care about this in your tests, so try it. But make sure you don't take this to production!
atime - totally useless (according to Nick) so turn it off in your filesystem.
After this the total test time is only 50 seconds.
Next, Nick switched to using RVM to install Ruby EE. He then implemented tcmalloc. He bumped up RUBY_HEAP_MIN_SLOTS as a setting on ruby EE from the default (10,000) to 1,000,000. This says "take a huge chunk of memory" to run our tests with. He bumped RUBY_GC_MALLOC_LIMIT up to 1,000,000,000. RUBY_HEAP_FREE_MIN went from 4,096 to 500,000. You can simply set this in your profile for testing.
After this, the total test time is 18 seconds. Quite a jump! And it looks relatively simple to implement. Right now, it only takes our project about 2 minutes to run our test suites. But once we get into Cucumber, time is going to increase rapidly.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment