Knapsack lets you run specs across parallel CI server nodes based on each spec file's time execution. Significantly speed up your tests with Knapsack.
A year ago, we started a new project.
As usual, the beginning was fun: small codebase, simple logic, and quick tests.
A few months of entropy later, our test suite reached 12 minutes.
That was annoying!
We chose the simple way out: throw money at the problem.
We added a few extra CI nodes and assigned an equal amount of test files each. Some specs, like unit tests, were quick and others, like end-to-end tests, took way more time.
That’s how we ended up with three fast CI nodes and one very slow:
That’s when we took the problem seriously and started coding.
We tried a few solutions, but found the best results by calculating the execution time of each test and splitting based on the last recorded times.
This strategy worked so well that I extracted Knapsack Pro into a gem, which owes its name to the Knapsack Problem.
With Knapsack Pro, our tests are split in the most efficient way so that each CI node finishes at the same time:
Add the gem to your project:
bundle add knapsack_pro --group "development, test"
Use the following code at the beginning of your spec/rails_helper.rb:
require 'knapsack_pro'
KnapsackPro::Adapters::RSpecAdapter.bind
Generate an API token and configure your CI server:
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=MY_API_TOKEN \
bundle exec rake knapsack_pro:queue:rspec
Profit!
Oh, and one more thing, check the docs because Knapsack Pro comes with a truckload of additional features.
We don’t just build software, we understand your business context, challenges, and users needs so everything we create, benefits your business.