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

Add support for more than one isolated process. #779

Merged
merged 15 commits into from Sep 16, 2020
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,10 @@

- None

## 3.2.1 - 2020-09-13

- Added support for multiple isolated processes.

v-kumar marked this conversation as resolved.
Show resolved Hide resolved
## 3.2.0 - 2020-08-27

### Breaking Changes
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Expand Up @@ -206,6 +206,7 @@ Options are:
-m, --multiply-processes [FLOAT] use given number as a multiplier of processes to run
-s, --single [PATTERN] Run all matching files in the same process
-i, --isolate Do not run any other tests in the group used by --single(-s)
--isolate-n How many processes to reserve for isolated tests. Default is 1.
--only-group INT[, INT]
-e, --exec [COMMAND] execute this code parallel and with ENV['TEST_ENV_NUMBER']
-o, --test-options '[OPTIONS]' execute test commands with those options
Expand Down
14 changes: 14 additions & 0 deletions lib/parallel_tests/cli.rb
Expand Up @@ -192,6 +192,12 @@ def parse_options!(argv)
options[:isolate] = true
end

opts.on("--isolate-n [PROCESSES]",
Integer,
"How many processes to reserve for isolated singles. By default it's one.") do |n|
options[:isolated_count] = n
end
v-kumar marked this conversation as resolved.
Show resolved Hide resolved

opts.on("--only-group INT[, INT]", Array) { |groups| options[:only_group] = groups.map(&:to_i) }

opts.on("-e", "--exec [COMMAND]", "execute this code parallel and with ENV['TEST_ENV_NUMBER']") { |path| options[:execute] = path }
Expand Down Expand Up @@ -255,6 +261,14 @@ def parse_options!(argv)
raise "--group-by #{allowed.join(" or ")} is required for --only-group"
end

if options[:isolate]
if options[:isolated_count].to_i > 0
raise "--isolate-n must be less than n" if options[:isolated_count] >= options[:count]
else
options[:isolated_count] = 1
end
end
v-kumar marked this conversation as resolved.
Show resolved Hide resolved

options
end

Expand Down
22 changes: 17 additions & 5 deletions lib/parallel_tests/grouper.rb
Expand Up @@ -15,13 +15,25 @@ def in_even_groups_by_size(items, num_groups, options= {})
groups = Array.new(num_groups) { {:items => [], :size => 0} }

# add all files that should run in a single process to one group
(options[:single_process] || []).each do |pattern|
matched, items = items.partition { |item, _size| item =~ pattern }
matched.each { |item, size| add_to_group(groups.first, item, size) }
single_process_patterns = options[:single_process] || []

single_items, items = items.partition do |item, _size|
single_process_patterns.any? { |pattern| item =~ pattern }
end

groups_to_fill = (options[:isolate] ? groups[1..-1] : groups)
group_features_by_size(items_to_group(items), groups_to_fill)
isolated_count = options[:isolate] ? (options[:isolated_count] || 1) : 0

if isolated_count >= 1
v-kumar marked this conversation as resolved.
Show resolved Hide resolved
# add all files that should run in a multiple isolated processes to their own groups
group_features_by_size(items_to_group(single_items), groups[0..(isolated_count - 1)])
# group the non-isolated by size
group_features_by_size(items_to_group(items), groups[isolated_count..-1])
else
# add all files that should run in a single non-isolated process to first group
single_items.each { |item, size| add_to_group(groups.first, item, size) }
# group all by size
group_features_by_size(items_to_group(items), groups)
end

groups.map! { |g| g[:items].sort }
end
Expand Down
4 changes: 4 additions & 0 deletions spec/parallel_tests/grouper_spec.rb
Expand Up @@ -54,6 +54,10 @@ def call(num_groups, options={})
expect(call(2, :single_process => [/1|2|3|4/])).to eq([["1", "2", "3", "4"], ["5"]])
end

it "groups single items into specified isolation groups" do
expect(call(3, :single_process => [/1|2|3|4/], :isolate => true, :isolated_count => 2)).to eq([["1", "4"], ["2", "3"], ["5"]])
end

it "groups single items with others if there are too few" do
expect(call(2, :single_process => [/1/])).to eq([["1", "3", "4"], ["2", "5"]])
end
Expand Down
20 changes: 20 additions & 0 deletions spec/parallel_tests/test/runner_spec.rb
Expand Up @@ -146,6 +146,26 @@ def call(*args)

expect(valid_combinations).to include(actual)
end

it "groups by size and use specified number of isolation groups" do
skip if RUBY_PLATFORM == "java"
expect(ParallelTests::Test::Runner).to receive(:runtimes).
and_return({"aaa1" => 1, "aaa2" => 3, "aaa3" => 2, "bbb" => 3, "ccc" => 1, "ddd" => 2})
result = call(["aaa1", "aaa2", "aaa3", "bbb", "ccc", "ddd", "eee"], 4, isolate: true, isolated_count: 2, single_process: [/^aaa/], group_by: :runtime)

isolated_1, isolated_2, *groups = result
expect(isolated_1).to eq(["aaa2"])
expect(isolated_2).to eq(["aaa1", "aaa3"])
actual = groups.map(&:to_set).to_set

# both eee and ccs are the same size, so either can be in either group
valid_combinations = [
[["bbb", "eee"], ["ccc", "ddd"]].map(&:to_set).to_set,
[["bbb", "ccc"], ["eee", "ddd"]].map(&:to_set).to_set
]

expect(valid_combinations).to include(actual)
end
end
end

Expand Down