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
20 changes: 10 additions & 10 deletions lib/parallel_tests/cli.rb
Expand Up @@ -190,12 +190,20 @@ def parse_options!(argv)
"Do not run any other tests in the group used by --single(-s)") do |pattern|

options[:isolate] = true
options[:isolate_count] = 1
v-kumar marked this conversation as resolved.
Show resolved Hide resolved
end

opts.on("--isolate-n [PROCESSES]",
Integer,
"Number of processes to use for isolated singles, default: 1") do |n|
options[:isolated_count] = n
"Number of processes to use for isolated singles, default: 1. Do not set this without setting --isolate.") do |n|
v-kumar marked this conversation as resolved.
Show resolved Hide resolved

# isolate_count is dependent on isolate being set.
abort "Don't use isolate-n without isolate" unless options[:isolate]
v-kumar marked this conversation as resolved.
Show resolved Hide resolved
if n >= ParallelTests.determine_number_of_processes(options[:count])
v-kumar marked this conversation as resolved.
Show resolved Hide resolved
abort 'Number of isolated processes must be less than total the number of processes'
end

options[:isolate_count] = n
end

opts.on("--only-group INT[, INT]", Array) { |groups| options[:only_group] = groups.map(&:to_i) }
Expand Down Expand Up @@ -261,14 +269,6 @@ 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

options
end

Expand Down
9 changes: 5 additions & 4 deletions lib/parallel_tests/grouper.rb
Expand Up @@ -21,16 +21,17 @@ def in_even_groups_by_size(items, num_groups, options= {})
single_process_patterns.any? { |pattern| item =~ pattern }
end

isolated_count = options[:isolate] ? (options[:isolated_count] || 1) : 0
if options[:isolate]
isolate_count = options[:isolate_count] || 1

if isolated_count >= 1
# 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_features_by_size(items_to_group(single_items), groups[0..(isolate_count - 1)])
# group the non-isolated by size
group_features_by_size(items_to_group(items), groups[isolated_count..-1])
group_features_by_size(items_to_group(items), groups[isolate_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
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/rails51/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: ../../..
specs:
parallel_tests (2.32.0)
parallel_tests (3.2.0)
parallel

GEM
Expand Down Expand Up @@ -65,7 +65,7 @@ GEM
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
parallel (1.19.1)
parallel (1.19.2)
rack (2.0.5)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/rails52/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: ../../..
specs:
parallel_tests (2.32.0)
parallel_tests (3.2.0)
parallel

GEM
Expand Down Expand Up @@ -72,7 +72,7 @@ GEM
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
parallel (1.19.1)
parallel (1.19.2)
rack (2.0.5)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand Down
32 changes: 32 additions & 0 deletions spec/parallel_tests/cli_spec.rb
Expand Up @@ -107,6 +107,38 @@ def call(*args)
end
end

context "single and isolate" do
it "single_process should be an array of patterns" do
expect(call(["test", "--single", '1'])).to eq(defaults.merge(single_process: [/1/]))
end

it "single_process should be an array of patterns" do
expect(call(["test", "--single", '1', "--single", '2'])).to eq(defaults.merge(single_process: [/1/, /2/]))
end

it "isolate should set isolate_count defaults" do
expect(call(["test", "--single", '1', "--isolate"])).to eq(defaults.merge(single_process: [/1/], isolate: true, isolate_count: 1))
end

it "isolate_n should set isolate_count" do
expect(call(["test", "-n", "3", "--single", '1', "--isolate", "--isolate-n", "2"])).to eq(
defaults.merge(count: 3, single_process: [/1/], isolate: true, isolate_count: 2)
)
end

it "isolate_n should not be set without isolate" do
expect(subject).to receive(:abort).with("Don't use isolate-n without isolate")

call(["test", "-n", "3", "--single", '1', "--isolate-n", "2"])
end

it "isolate_n must be within limits" do
expect(subject).to receive(:abort).with("Number of isolated processes must be less than total the number of processes")

call(["test", "-n", "3", "--single", '1', "--isolate", "--isolate-n", "3"])
end
end

context "when the -- option separator is used" do
it "interprets arguments as files/directories" do
expect(call(%w(-- test))).to eq( files: %w(test))
Expand Down
2 changes: 1 addition & 1 deletion spec/parallel_tests/grouper_spec.rb
Expand Up @@ -55,7 +55,7 @@ def call(num_groups, options={})
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"]])
expect(call(3, :single_process => [/1|2|3|4/], :isolate => true, :isolate_count => 2)).to eq([["1", "4"], ["2", "3"], ["5"]])
end

it "groups single items with others if there are too few" do
Expand Down
2 changes: 1 addition & 1 deletion spec/parallel_tests/test/runner_spec.rb
Expand Up @@ -151,7 +151,7 @@ def call(*args)
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)
result = call(["aaa1", "aaa2", "aaa3", "bbb", "ccc", "ddd", "eee"], 4, isolate: true, isolate_count: 2, single_process: [/^aaa/], group_by: :runtime)

isolated_1, isolated_2, *groups = result
expect(isolated_1).to eq(["aaa2"])
Expand Down