Skip to content

Commit

Permalink
Support specifying number of processes to use
Browse files Browse the repository at this point in the history
Usage: turbo_tests -n [PROCESSES]
  • Loading branch information
ilyazub committed Oct 30, 2020
1 parent 7ef28fd commit c19d02b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
turbo_tests (0.1.0)
turbo_tests (1.1.0)
optparse
parallel_tests
rspec
Expand All @@ -26,7 +26,7 @@ GEM
rspec-mocks (~> 3.9.0)
rspec-core (3.9.3)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.3)
rspec-expectations (3.9.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,20 @@ Show help:
```bash
$ bundle exec turbo_tests -h
Usage: turbo_tests [options]

[optional] Only selected files & folders:
turbo_tests spec/bar spec/baz/xxx_spec.rb

Options:
-n [PROCESSES] How many processes to use, default: available CPUs
-r, --require PATH Require a file.
-f, --format FORMATTER Choose a formatter.
-f, --format FORMATTER Choose a formatter. Available formatters: progress (p), documentation (d). Default: progress
-t, --tag TAG Run examples with the specified tag.
-o, --out FILE Write output to a file instead of $stdout
-v, --verbose More output
--fail-fast=[N]
```

## Roadmap
- [ ] Capture time to load files #1

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down
21 changes: 19 additions & 2 deletions lib/turbo_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,31 @@ def run
requires = []
formatters = []
tags = []
count = nil
verbose = false
fail_fast = nil

OptionParser.new { |opts|
opts.banner = <<-BANNER.gsub(/^ /, "")
Run all tests in parallel, giving each process ENV['TEST_ENV_NUMBER'] ('1', '2', '3', ...).
Uses parallel_tests under the hood, but reports test results incrementally. Based on Discourse and RubyGems work in this area.
Usage: turbo_tests [options]
[optional] Only selected files & folders:
turbo_tests spec/bar spec/baz/xxx_spec.rb
Options:
BANNER

opts.on("-n [PROCESSES]", Integer, "How many processes to use, default: available CPUs") { |n| count = n }

opts.on("-r", "--require PATH", "Require a file.") do |filename|
requires << filename
end

opts.on("-f", "--format FORMATTER", "Choose a formatter.") do |name|
opts.on("-f", "--format FORMATTER", "Choose a formatter. Available formatters: progress (p), documentation (d). Default: progress") do |name|
formatters << {
name: name,
outputs: []
Expand Down Expand Up @@ -76,7 +92,8 @@ def run
tags: tags,
files: @argv.empty? ? ["spec"] : @argv,
verbose: verbose,
fail_fast: fail_fast
fail_fast: fail_fast,
count: count,
)
end
end
Expand Down
8 changes: 6 additions & 2 deletions lib/turbo_tests/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.run(opts = {})
start_time = opts.fetch(:start_time) { Time.now }
verbose = opts.fetch(:verbose, false)
fail_fast = opts.fetch(:fail_fast, nil)
count = opts.fetch(:count, nil)

reporter = Reporter.from_config(formatters, start_time)

Expand All @@ -21,7 +22,8 @@ def self.run(opts = {})
files: files,
tags: tags,
verbose: verbose,
fail_fast: fail_fast
fail_fast: fail_fast,
count: count
).run
end

Expand All @@ -31,6 +33,8 @@ def initialize(opts)
@tags = opts[:tags]
@verbose = opts[:verbose]
@fail_fast = opts[:fail_fast]
@count = opts[:count]

@failure_count = 0
@runtime_log = "tmp/parallel_runtime_rspec.log"

Expand All @@ -39,7 +43,7 @@ def initialize(opts)
end

def run
@num_processes = ParallelTests.determine_number_of_processes(nil)
@num_processes = ParallelTests.determine_number_of_processes(@count)

tests_in_groups =
ParallelTests::RSpec::Runner.tests_in_groups(
Expand Down
2 changes: 1 addition & 1 deletion lib/turbo_tests/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TurboTests
VERSION = "1.0.0"
VERSION = "1.1.0"
end
2 changes: 1 addition & 1 deletion turbo_tests.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
spec.name = "turbo_tests"
spec.version = TurboTests::VERSION
spec.authors = ["Ilya Zub"]
spec.email = ["ilya@serpapi.com"]
spec.email = ["zaoooza92@gmail.com"]

spec.summary = "Runner for grosser/parallel_tests with incremental summarized output. Based on Discourse and Rubygems work in this area."
spec.homepage = "https://github.com/serpapi/turbo_tests"
Expand Down

0 comments on commit c19d02b

Please sign in to comment.