Dylan Andrews
Dylan Andrews

Reputation: 296

Spring rspec not speeding up tests

Running a single test in our test suite takes anywhere from 20 - 30 seconds. Prior to adding spring and spring-commands-rspec, the output from running a test would look like this.

Finished in 21.99 seconds (files took 21.64 seconds to load)
1 example, 0 failures

Randomized with seed 52406

The 22 second file load time suggested that adding the aforementioned gems would help, but after doing so the test is still just as slow (I am running with bundle exec spring rspec [path_to_spec]. The new output (see below) suggests the file time has in fact been drastically improved (down from 21.64 seconds to 1.25 seconds), but the overall speed of the test is basically the same. This seems very odd and unexpected based on what I have read about the expected effects of adding these gems.

Finished in 21.86 seconds (files took 1.25 seconds to load)
1 example, 0 failures

Randomized with seed 7594

Any thoughts on why the test is still just as slow, and does anyone have tips on how to fix this/speed up the test? Thanks.

Upvotes: 0

Views: 576

Answers (1)

ScottM
ScottM

Reputation: 10414

This is what I'd expect, to be honest. Spring's raison d'être is to speed up the loading of files -- and once RSpec starts running, Spring's job is done. And it's done quite a job – going from 21.64 seconds to 1.25 is pretty good!

Now you can concentrate on what RSpec is doing and how to speed that up. While RSpec does have a --profile option which will tell you which examples are running the slowest, in your output above you only have one example so that's not going to tell you anything you don't already know.

If it's a system test that is spending that time in getting some form of headless browser to start up, say, then you may find that adding more tests don't double or triple the running time because the setup is shared across tests and the impression of a 'slow test suite' might fade. On the other hand, if the example that's running slow is a unit test I'd be very concerned.

This post on the Evil Martians website has some pointers for looking at where the slow patches of whole test suites are (mostly involving the TestProf gem). It's probably overkill for a single test, but if you run out of other ways to find clues you might find some use in it.

Upvotes: 2

Related Questions