Parallel your specs

A long time ago

many, many commits ago

Build was green

and fast :)

Tests were even faster


But winter finally came

Actually it was summer


and build was slow :-(

Save time

&

get faster feedback

Parallel specs

splitting your test suite


Test suite example


1_fast_spec.rb
2_fast_spec.rb
3_fast_spec.rb
4_fast_spec.rb

5_slow_spec.rb
6_slow_spec.rb
7_slow_spec.rb

8_super_slow_spec.rb

Balancing

split all test files across N nodes:


Node 1

1_fast_spec.rb
2_fast_spec.rb

Node 2

3_fast_spec.rb
4_fast_spec.rb

Node 3

5_slow_spec.rb
6_slow_spec.rb

Node 4

7_slow_spec.rb

8_super_slow_spec.rb

It ends up like this...


Time for the rescue



let's split tests based on the time execution
with Knapsack gem

The Epic Split



Node 1

8_super_slow_spec.rb



Node 2

7_slow_spec.rb
4_fast_spec.rb
1_fast_spec.rb

Node 3

6_slow_spec.rb
3_fast_spec.rb

Node 4

5_slow_spec.rb

2_fast_spec.rb


How about time


How to set up Knapsack?


# Gemfilegem 'knapsack'


spec_helper.rb


require 'knapsack'Knapsack::Adapters::RspecAdapter.bind


Rakefile


require 'knapsack' Knapsack.load_tasks


Generate time execution report

for your spec files


$ KNAPSACK_GENERATE_REPORT=true \ bundle exec rspec spec


run it on CI machine

Commit generated report

into your repository


knapsack_report.json

Setup your CI server


$ CI_NODE_TOTAL=2 CI_NODE_INDEX=0 \ bundle exec rake knapsack:rspec


Note for CircleCI users

circleci.yml

test:  override:    - bundle exec rake knapsack:rspec: # required colon at the end        parallel: true # 4 spaces indentation

github.com/ArturT/knapsack




badly needed


Happy coding



Sources:

Why knapsack?



Artur Trzop lunarlogic.io
VII 2014

Knapsack to parallel your specs

By ArturT

Knapsack to parallel your specs

Parallel specs across CI server nodes based on each spec file's time execution.

  • 1,425
Loading comments...

More from ArturT