Speed up your Travis CI test runs with WAD

Manfred Stienstra

There are three major influences on the total runtime of your test suite. Downloading code, installing dependencies, and running the actual suite.

Fortunately Travis already takes care of checking out and caching your GitHub repository. In previous articles we've already talked about speeding up your suite.

That leaves installing dependencies. They need to be downloaded, possibly compiled, and installed. That takes time.

Most Rails and Ruby projects install all their dependencies using Bundler. This makes it an easy target for optimization. We're definitely not the first to notice this. Both Matias Korhonen and Michał Czyż already proposed a similar solution. WAD is different because it's ready to be added to the project with minimal setup.

You only need to drop the WAD script in the bin/ or script/ directory of your project and swap out Bundler for WAD in your Travis configuration.

install: "bin/wad"
script: "bundle exec rake test:all"
env:
  - S3_BUCKET_NAME=unique-wad-bucket-name
  - S3_REGION=eu-west-1
  - secure: "OTpNPEmXlMm70P4y6sE419Rr…"
Configure Travis to use WAD instead of Bundler to install the bundle.

You can find detailed setup instructions in the project's README on GitHub.

On every run WAD tries to fetch the bundle from a configured S3 bucket. When the bundle hasn't been cached yet it calls Bundler and creates a tarball of the .bundle directory. After installing the bundle WAD pushes the tarball to S3. On every next run the tarball is downloaded and unpacked.

We get automatic cache invalidation by basing the bundle name on the contents of Gemfile.lock, the Ruby version, and the Ruby platform.

Time saved by using WAD depends on the amount of dependencies and install times of the gems. On an average project it will probably save you around two minutes.

Please give it a try and let us know if you run into any trouble.