Maybe you use CircleCI parallelisation to run your test suite across multiple CI nodes but you noticed that some CI nodes take more time to complete tests than the others.

parallel testing

This can happen when your tests have random time. Often E2E (end-to-end) tests have a more random time of execution because the browser has to wait for some elements to be loaded on the website or maybe your app is depended on external API and processing requests have different duration. Other reason can be a delay with starting one of your parallel CI nodes.

Default CircleCI test suite split

Here is an example of running tests with default CircleCI parallelisation. As you can see the whole CI build finished work in 29 minutes 37 seconds. Tests were executed on 15 parallel CI nodes and some of them run tests for 14 minutes and the slowest one for almost 30 minutes.

parallel tests CircleCI without knapsack

If we could auto-balance the split of test suite across CI nodes in a way that all CI nodes do work in similar time then we could get shorter CI build.

Dynamic test suite split

We can split tests in a dynamic way across CI nodes using Knapsack Pro. For instance, we can split tests for RSpec or Minitest in Ruby. If you run E2E tests with Cypress test runner then you can split Javascript tests as well.

Here is graph after adding Knapsack Pro Queue Mode. Knapsack Pro Queue Mode keeps your tests auto-balanced across CI nodes in order to allow all CI nodes finish work in similar time. As you can see CI build took 22 minutes 50 seconds instead of almost 30 minutes. It means we saved 7 minutes per each CI build.

parallel tests CircleCI with Knapsack Pro

When your team runs 20 CI builds per day you could save 2 hours 20 minutes every day. It’s over 46 hours saved during a month.

In below video I show what else problems can be solved with dynamic test suite split.

If you use RSpec then you can even auto split slow RSpec test files by test examples on parallel jobs thanks to knapsack_pro gem. It means your single slow spec file can run in parallel!

You can also read more about it at Knapsack Pro and see support for more test runners there.

Other tips

If you are curious about Cypress test suite split.

If you would like to run your CircleCI 2.0 tests with Chrome headless.

Tech details how to run tests in Minitest continuously with dynamic test files loading.

If you are looking for an optimal CI solution for your project, check out our comparisons of Circle CI vs other CI providers. Most popular comparisons include Circle CI vs Github Actions, Circle CI vs CodeFresh CI, Circle CI vs Gitlab CI, and Circle CI vs Bitbucket Pipelines.