Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parallel_test options: pattern, exclude-pattern & group-by #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Options:
--seed SEED Seed for rspec
```

To pass any options supported by paralell_tests, use `--` :

```bash
bundle exec turbo_tests -n 4 -- --only-group 1 --pattern spec/system
```

## 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
12 changes: 8 additions & 4 deletions lib/turbo_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,20 @@ def run
end
end

success = TurboTests::Runner.run(
parallel_options = ParallelTests::CLI.new.send(:parse_options!, @argv.unshift("--type", "rspec"))
files = parallel_options.fetch(:files, ["spec"])

success = TurboTests::Runner.run({
formatters: formatters,
tags: tags,
files: @argv.empty? ? ["spec"] : @argv,
files: files,
runtime_log: runtime_log,
verbose: verbose,
fail_fast: fail_fast,
count: count,
seed: seed
)
seed: seed,
parallel_options: parallel_options
})

if success
exit 0
Expand Down
23 changes: 9 additions & 14 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 = {})
files = opts[:files]
formatters = opts[:formatters]
tags = opts[:tags]
parallel_options = opts[:parallel_options]

# SEE: https://bit.ly/2NP87Cz
start_time = opts.fetch(:start_time) { Process.clock_gettime(Process::CLOCK_MONOTONIC) }
Expand All @@ -38,15 +39,15 @@ def self.run(opts = {})
fail_fast: fail_fast,
count: count,
seed: seed,
seed_used: seed_used
seed_used: seed_used,
parallel_options: parallel_options
).run
end

def initialize(opts)
@reporter = opts[:reporter]
@files = opts[:files]
@tags = opts[:tags]
@runtime_log = opts[:runtime_log] || "tmp/turbo_rspec_runtime.log"
@verbose = opts[:verbose]
@fail_fast = opts[:fail_fast]
@count = opts[:count]
Expand All @@ -56,6 +57,10 @@ def initialize(opts)
@seed = opts[:seed]
@seed_used = opts[:seed_used]

@runtime_log = opts[:runtime_log] || "tmp/turbo_rspec_runtime.log"
@parallel_options = opts.fetch(:parallel_options, {})
@parallel_options[:runtime_log] = @runtime_log

@messages = Thread::Queue.new
@threads = []
@error = false
Expand All @@ -67,27 +72,17 @@ def run
ParallelTests::RSpec::Runner.tests_with_size(@files, {}).size
].min

use_runtime_info = @files == ["spec"]
inkstak marked this conversation as resolved.
Show resolved Hide resolved

group_opts = {}

if use_runtime_info
group_opts[:runtime_log] = @runtime_log
else
group_opts[:group_by] = :filesize
end

tests_in_groups =
ParallelTests::RSpec::Runner.tests_in_groups(
@files,
@num_processes,
**group_opts
@parallel_options
)

setup_tmp_dir

subprocess_opts = {
record_runtime: use_runtime_info
record_runtime: @parallel_options[:group_by] == :runtime
Copy link
Author

@inkstak inkstak Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's record runtime log only when --group-by runtime is passed.

Not sure if this line is still relevant...

}

report_number_of_tests(tests_in_groups)
Expand Down