Knapsack Pro

Check out the new docs for the updated documentation.

FAQ / knapsack_pro / General questions for knapsack_pro gem

How to run tests for particular CI node in your development environment

for knapsack_pro Regular Mode

In your development environment you can debug tests that were run on the particular CI node. For instance to run subset of tests for the first CI node with specified seed you can do.


KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=token \
KNAPSACK_PRO_REPOSITORY_ADAPTER=git \
KNAPSACK_PRO_PROJECT_DIR=~/projects/rails-app \
KNAPSACK_PRO_CI_NODE_TOTAL=2 \
KNAPSACK_PRO_CI_NODE_INDEX=0 \
bundle exec rake "knapsack_pro:rspec[--seed 123]"

Above example is for RSpec. You can use respectively rake task name and token environment variable when you want to run tests for minitest, test_unit, cucumber or spinach. It should work when all CI nodes finished work and sent time execution data to Knapsack Pro API. You can visit user dashboard to preview particular CI build and ensure time execution data were collected from all CI nodes. If at least one CI node has not sent time execution data to the Knapsack Pro API then you should check below solution.

Check test runner output on particular CI node you would like to retry in development. You should see at the beginning of rspec command an output that can be copied and executed in development.

/Users/ubuntu/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.4.4/exe/rspec spec/foo_spec.rb spec/bar_spec.rb --default-path spec

Command similar to above can be executed in your development this way:


bundle exec rspec spec/foo_spec.rb spec/bar_spec.rb --default-path spec

If you were running your tests with --order random on your CI then you can additionaly pass seed param with proper value in above command (--seed 123).

for knapsack_pro Queue Mode

There are a few ways to reproduce tests executed on CI node in your development environment.

  • At the end of knapsack_pro:queue:rspec results you will find example of command that you can copy and paste to your development machine. It will run all tests executed on the CI node in a single run. I recommend this approach.

  • For each intermediate request to Knapsack Pro API queue you will also find example of command to run a subset of tests fetched from API. This might be helpful when you use --order random for rspec and you would like to reproduce the tests with the same seed.

  • You can also retry tests and record the time execution data for them again for the particular CI node. Note you must be checkout on the same branch and git commit as your CI node was.

    To retry the particular CI node do this on your machine:

    
    RACK_ENV=test \
    RAILS_ENV=test \
    KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=token \
    KNAPSACK_PRO_REPOSITORY_ADAPTER=git \
    KNAPSACK_PRO_PROJECT_DIR=~/projects/rails-app \
    KNAPSACK_PRO_CI_NODE_TOTAL=2 \
    KNAPSACK_PRO_CI_NODE_INDEX=0 \
    KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true \
    bundle exec rake "knapsack_pro:queue:rspec"
    
    

    If you were running your tests with --order random on your CI like this:

    
    bundle exec rake "knapsack_pro:queue:rspec[--order random]"
    
    

    Then you can find the seed number visible in rspec output:

    (...)
    Randomized with seed 123
    

    You can pass the seed in your local environment to reproduce the tests in the same order as they were executed on CI node:

    
    RACK_ENV=test \
    RAILS_ENV=test \
    KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=token \
    KNAPSACK_PRO_REPOSITORY_ADAPTER=git \
    KNAPSACK_PRO_PROJECT_DIR=~/projects/rails-app \
    KNAPSACK_PRO_CI_NODE_TOTAL=2 \
    KNAPSACK_PRO_CI_NODE_INDEX=0 \
    KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true \
    bundle exec rake "knapsack_pro:queue:rspec[--seed 123]"
    
    

# General questions for knapsack_pro gem
See questions outside of this category

Start using Knapsack Pro

Sign up and speed up your tests.