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

Allow for duplicate tests with --allow-duplicates #940

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Add `--allow-duplicates` flag to support re-running 1 spec multiple times

### Breaking Changes

Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ Options are:
--nice execute test commands with low priority.
--runtime-log [PATH] Location of previously recorded test runtimes
--allowed-missing [INT] Allowed percentage of missing runtimes (default = 50)
--allow-duplicates When detecting files to run, allow duplicates. Useful for local debugging
--unknown-runtime [FLOAT] Use given number as unknown runtime (otherwise use average time)
--first-is-1 Use "1" as TEST_ENV_NUMBER to not reuse the default test environment
--fail-fast Stop all groups when one group fails (best used with --test-options '--fail-fast' if supported
Expand Down
1 change: 1 addition & 0 deletions lib/parallel_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def parse_options!(argv)
opts.on("--nice", "execute test commands with low priority.") { options[:nice] = true }
opts.on("--runtime-log [PATH]", "Location of previously recorded test runtimes") { |path| options[:runtime_log] = path }
opts.on("--allowed-missing [INT]", Integer, "Allowed percentage of missing runtimes (default = 50)") { |percent| options[:allowed_missing_percent] = percent }
opts.on('--allow-duplicates', 'When detecting files to run, allow duplicates') { options[:allow_duplicates] = true }
opts.on("--unknown-runtime [FLOAT]", Float, "Use given number as unknown runtime (otherwise use average time)") { |time| options[:unknown_runtime] = time }
opts.on("--first-is-1", "Use \"1\" as TEST_ENV_NUMBER to not reuse the default test environment") { options[:first_is_1] = true }
opts.on("--fail-fast", "Stop all groups when one group fails (best used with --test-options '--fail-fast' if supported") { options[:fail_fast] = true }
Expand Down
7 changes: 5 additions & 2 deletions lib/parallel_tests/test/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ def find_tests(tests, options = {})
suffix_pattern = options[:suffix] || test_suffix
include_pattern = options[:pattern] || //
exclude_pattern = options[:exclude_pattern]
allow_duplicates = options[:allow_duplicates]

(tests || []).flat_map do |file_or_folder|
files = (tests || []).flat_map do |file_or_folder|
if File.directory?(file_or_folder)
files = files_in_folder(file_or_folder, options)
files = files.grep(suffix_pattern).grep(include_pattern)
Expand All @@ -248,7 +249,9 @@ def find_tests(tests, options = {})
else
file_or_folder
end
end.uniq
end

allow_duplicates ? files : files.uniq
end

def files_in_folder(folder, options = {})
Expand Down
4 changes: 4 additions & 0 deletions spec/parallel_tests/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def call(*args)
.to eq(defaults.merge(first_is_1: true))
end

it "parses allow-duplicates" do
expect(call(["test", "--allow-duplicates"])).to eq(defaults.merge(allow_duplicates: true))
end

context "parse only-group" do
it "group_by should be set to filesize" do
expect(call(["test", "--only-group", '1'])).to eq(defaults.merge(only_group: [1], group_by: :filesize))
Expand Down
4 changes: 4 additions & 0 deletions spec/parallel_tests/test/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ def call(*args)
it "discards duplicates" do
expect(call(['baz', 'baz'])).to eq(['baz'])
end

it "keeps duplicates when allow_duplicates" do
expect(call(['baz', 'baz'], allow_duplicates: true)).to eq(['baz', 'baz'])
end
end

describe ".summarize_results" do
Expand Down