Git Product home page Git Product logo

test-boosters's Introduction

Test Boosters

Gem Version Build Status

Auto Parallelization — runs test files in multiple jobs

Test Booster basics:

Test Boosters:

Installation

gem install semaphore_test_boosters

What are Test Boosters

Test Boosters take your test suite and split the test files into multiple jobs. This allows you to quickly parallelize your test suite across multiple build machines.

As an example, let's take a look at the rspec_booster --job 1/10 command. It lists all the files that match the spec/**/*_spec.rb glob in your project, distributes them into 10 jobs, and execute the first job.

Split Configuration

Every test booster can load a split configuration file that helps the test booster to make a better distribution.

For example, if you have 3 RSpec Booster jobs, and you want to run:

  • spec/a_spec.rb and spec/b_spec.rb in the first job
  • spec/c_spec.rb and spec/d_spec.rb in the second job
  • spec/e_spec.rb in the third job

you should put the following in your split configuration file:

[
  { "files": ["spec/a_spec.rb", "spec/b_spec.rb"] },
  { "files": ["spec/c_spec.rb", "spec/d_spec.rb"] },
  { "files": ["spec/e_spec.rb"] }
]

Semaphore Classic uses Split configurations to split your test files based on their durations in the previous builds.

NOTE

Distributing tests based on their duration is not supported in Semaphore 2.0. If you use Semaphore 2.0, provide a split configuration file to achieve the best performance.

Leftover Files

Files that are part of your test suite, but are not in the split configuration file, are called "leftover files". These files will be distributed based on their file size in a round robin fashion across your jobs.

For example, if you have the following in your split configuration:

[
  { "files": ["spec/a_spec.rb"] }
  { "files": ["spec/b_spec.rb"] }
  { "files": ["spec/c_spec.rb"] }
]

and the following files in your spec directory:

# Files from split configuration ↓

spec/a_spec.rb
spec/b_spec.rb
spec/c_spec.rb

# Leftover files ↓

spec/d_spec.rb
spec/e_spec.rb

When you run the rspec_booster --job 1/3 command, the files from the configuration's first job and some leftover files will be executed.

rspec_booster --job 1/3

# => runs: bundle exec rspec spec/a_spec.rb spec/d_spec.rb

Booster will distribute your leftover files uniformly across jobs.

RSpec Booster

The rspec_booster loads all the files that match the spec/**/*_spec.rb pattern and uses the ~/rspec_split_configuration.json file to parallelize your test suite.

Example of running job 4 out of 32 jobs:

rspec_booster --job 4/32

Under the hood, the RSpec Booster uses the following command:

bundle exec rspec --format documentation --format json --out /home/<user>/rspec_report.json <file_list>

Optionally, you can pass additional RSpec flags with the TB_RSPEC_OPTIONS environment variable. You can also set a RSpec formatter with the TB_RSPEC_FORMATTER environment variable. Default formatter is documentation.

Example:

TB_RSPEC_OPTIONS='--fail-fast=3' TB_RSPEC_FORMATTER=Fivemat rspec_booster --job 4/32

# will execute:
bundle exec rspec --fail-fast=3 --format Fivemat --format json --out /home/<user>/rspec_report.json <file_list>

Cucumber Booster

The cucumber_booster loads all the files that match the features/**/*.feature pattern and uses the ~/cucumber_split_configuration.json file to parallelize your test suite.

Example of running job 4 out of 32 jobs:

cucumber_booster --job 4/32

Under the hood, the Cucumber Booster uses the following command:

bundle exec cucumber <file_list>

Minitest Booster

The minitest_booster loads all the files that match the test/**/*_test.rb pattern and uses the ~/minitest_split_configuration.json file to parallelize your test suite.

Example of running job 4 out of 32 jobs:

minitest_booster --job 4/32

If minitest booster is executed in a scope of a Rails project, the following is executed:

bundle exec rails test <file_list>

If minitest booster is running outside of a Rails project, the following is executed:

ruby -e 'ARGV.each { |f| require ".#{f}" }' <file_list>

If you want to run a custom command for minitest, use the MINITEST_BOOSTER_COMMAND environment variable:

export MINITEST_BOOSTER_COMMAND="bundle exec rake test"

minitest_booster --job 1/42

ExUnit Booster

The ex_unit_booster loads all the files that match the test/**/*_test.exs pattern and uses the ~/ex_unit_split_configuration.json file to parallelize your test suite.

Example of running job 4 out of 32 jobs:

ex_unit_booster --job 4/32

Under the hood, the ExUnit Booster uses the following command:

mix test <file_list>

Go Test Booster

The go_test_booster loads all the files that match the **/*_test.go pattern and uses the ~/go_test_split_configuration.json file to parallelize your test suite.

Example of running job 4 out of 32 jobs:

go_test_booster --job 4/32

Under the hood, the Go Test Booster uses the following command:

go test <file_list>

Development

Integration testing

For integration tests we use test repositories that are located in https://github.com/renderedtext/test-boosters-tests.git.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/renderedtext/test-boosters.

License

The gem is available as open source under the terms of the MIT License.

test-boosters's People

Contributors

justinbburris avatar mattrym avatar ndbroadbent avatar shiroyasha avatar vonum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

test-boosters's Issues

Support for ./.rspec_split_configuration.json

Hello,

Would it be possible add default support for ./.rspec_split_configuration.json, in the local directory? I'm going to set this manually in RSPEC_SPLIT_CONFIGURATION_PATH, but I think it would be a good default for when tests are being run on CI. Thanks!

returns `bundler: command not found: rspec` on gitlab runner

Hey Team,

I tried to integrate with gitlab ci but it showed bundler: command not found: rspec after run this command
time bundle exec rspec_booster --job $CI_NODE_INDEX/$CI_NODE_TOTAL

it can be fixed by removing the with_clean_env
wenjieyek@d72a3f2

But not sure is the best approach for fixing this. Hope the team can give some idea.

Thanks!

http command not found when used outside of SemaphoreCI

Is this gem meant to be used outside of SemaphoreCI?

We are encountering an issue with the after_job method that uploads insights to SemaphoreCI because of a missing http shell command.

Is it possible to make this a configuration parameter? I'm happy to submit a PR for it.

Boosting Cucumber

Split notes. Cucumber text consider a different version, appreciate it. Banana split, YOU! Parameter neutralize.

cucumber booster doesn't read cucumber_split_configuration.json and runs all files in leftover mode

=== Test Booster v2.7.0 - Job 1 out of 3 ====

Ruby Version: 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
Bundler Version: 2.1.2
Cucumber Version: 5.0.0
Found Cucumber profile file: /Users/jshah/forum-ui/ui_tests/cucumber.yml
Found Cucumber profile file: /Users/jshah/forum-ui/ui_tests/cucumber.yml
Inserting Semaphore configuration for json report
Report path: /Users/jshah/cucumber_report.json
Appending Semaphore profile to default profile
Split configuration present: no
Split configuration valid: yes
Split configuration file count: 0

Deprecation: Bundler.with_clean_env

[DEPRECATED] `Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env` (called at /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/semaphore_****_boosters-2.6.0/lib/****_boosters/shell.rb:32)

It is being triggered by this code: https://github.com/renderedtext/test-boosters/blob/master/lib/test_boosters/shell.rb#L32

    def with_clean_env
      defined?(Bundler) ? Bundler.with_clean_env { yield } : yield
    end

RSpec seed

In order to actually reproduce some types of failures that we see in CI, in addition to running the same booster group number, we need to run it with the same seed, so that within the group the tests are ordered the same way, and leaking state issues can be isolated.

bundle exec rspec_booster --job $BOOSTER_NUM/$CIRCLE_NODE_TOTAL

=== Test Booster v2.6.0 - Job 4 out of 7 ====
...

Randomized with seed 20575

With standard RSpec we can provide a --seed option on the command line.

Please consider supporting:

--order defined
--order rand
--order rand:123
--seed 123 # same as --order rand:123

as it is the only way we can repro issues locally!

bundle exec does find the command rspec_booster

Hi,

I have added the gem to my rails Gemfile and ran the bundle install. And when I try to bundle exec rspec_booster --job 1/50 it shows: command not found: rspec_booster

However when I gem install semaphore_test_boosters, the executables are now available. Is it something to be expected? I couldn't see in the docs how to generate those executables to be found by bundler.

Pass test file pattern via the TEST_FILE_PATTERN environment variable

RSpec booster runs all specs which match spec/**/*_spec.rb path.
Cucumber booster runs all features within features/**/*.feature path.

It would be useful if you could specify subdirectory from which you want your specs to be included.

Currently, this can be achieved by moving all unwanted test files before Booster is run.

--tags option can't be passed in

running cucumber_booster --job 10/15 --tags 'not @flaky' results in:

lib/test_boosters/cli_parser.rb:36:in parse': invalid option: --tags (OptionParser::InvalidOption)`

Privacy/Security concern: make it clear that a report file is uploaded to https://semaphoreci.com/

I was exploring the codebase of this gem, and I noticed the module InsightsUploader, which uploads a report file to https://semaphoreci.com. (https://github.com/renderedtext/test-boosters/blob/master/lib/test_boosters/insights_uploader.rb#L20 )

If we focus only on the RSpec generated reports, the formatter adds all text contained in the "examples", AND the comments below the examples.
Example:

context 'my first context' do
  # This is a comment to explain my test 
  it 'does something' do
  end
end

reports

# Not sure of the finale uploaded file, it's basically a custom RSpec formatter. 
{
  context: {
    text: 'my first context',
    childs: [{
      it: {
        comment: 'This is a comment to explain my test',
        text: 'does something'
      }
    }]
  }
}

Reporting might be fine, as long as:

  • It is explicit for the user that data is being used, what data is exported, what's the point of exporting that data
  • there is an option to disable the reporting.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.