Skip to content

Commit c1d7ecc

Browse files
authored
rename multiple env, fix float bug, ensure parsing works (#993)
1 parent 62c4d0f commit c1d7ecc

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### Added
88

9-
- Allow processor multiplier (flag: `-m` or `--multiply-processes`) to be set via the environment variable `PARALLEL_TEST_MULTIPLE`
9+
- Allow processor multiplier (flag: `-m` or `--multiply-processes`) to be set via the environment variable `PARALLEL_TEST_MULTIPLY_PROCESSES`
1010

1111
### Fixed
1212

lib/parallel_tests.rb

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,32 @@
66
module ParallelTests
77
WINDOWS = (RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
88
RUBY_BINARY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
9-
DEFAULT_MULTIPLE = 1.0
9+
DEFAULT_MULTIPLY_PROCESSES = 1.0
1010

1111
autoload :CLI, "parallel_tests/cli"
1212
autoload :VERSION, "parallel_tests/version"
1313
autoload :Grouper, "parallel_tests/grouper"
1414
autoload :Pids, "parallel_tests/pids"
1515

1616
class << self
17-
def determine_number_of_processes(count)
18-
[
19-
count,
20-
ENV["PARALLEL_TEST_PROCESSORS"],
21-
Parallel.processor_count
22-
].detect { |c| !c.to_s.strip.empty? }.to_i
17+
def determine_processor_count(count)
18+
Integer(
19+
[
20+
count,
21+
ENV["PARALLEL_TEST_PROCESSORS"],
22+
Parallel.processor_count
23+
].detect { |c| !c.to_s.strip.empty? }
24+
)
2325
end
2426

2527
def determine_multiple(multiple)
26-
[
27-
multiple,
28-
ENV["PARALLEL_TEST_MULTIPLE"],
29-
DEFAULT_MULTIPLE,
30-
].detect { |c| !c.to_s.strip.empty? }.to_f
28+
Float(
29+
[
30+
multiple,
31+
ENV["PARALLEL_TEST_MULTIPLY_PROCESSES"],
32+
DEFAULT_MULTIPLY_PROCESSES
33+
].detect { |c| !c.to_s.strip.empty? }
34+
)
3135
end
3236

3337
def with_pid_file

lib/parallel_tests/cli.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def run(argv)
1414

1515
ENV['DISABLE_SPRING'] ||= '1'
1616

17-
num_processes = ParallelTests.determine_number_of_processes(options[:count])
18-
num_processes *= ParallelTests.determine_multiple(options[:multiply])
17+
num_processes = ParallelTests.determine_processor_count(options[:count])
18+
num_processes = (num_processes * ParallelTests.determine_multiple(options[:multiply])).round
1919

2020
options[:first_is_1] ||= first_is_1?
2121

@@ -220,8 +220,8 @@ def parse_options!(argv)
220220
default - runtime when runtime log is filled otherwise filesize
221221
TEXT
222222
) { |type| options[:group_by] = type.to_sym }
223-
opts.on("-m COUNT", "--multiply-processes COUNT", Float, "use given number as a multiplier of processes to run") do |multiply|
224-
options[:multiply] = multiply
223+
opts.on("-m COUNT", "--multiply-processes COUNT", Float, "use given number as a multiplier of processes to run") do |m|
224+
options[:multiply_processes] = m
225225
end
226226

227227
opts.on("-s PATTERN", "--single PATTERN", "Run all matching files in the same process") do |pattern|

spec/parallel_tests_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
end
99

1010
def call(count)
11-
ParallelTests.determine_number_of_processes(count)
11+
ParallelTests.determine_processor_count(count)
1212
end
1313

1414
it "uses the given count if set" do
@@ -55,7 +55,7 @@ def call(multiple)
5555

5656
it "uses the processor multiple from ENV before Parallel" do
5757
ENV['PARALLEL_TEST_MULTIPLE'] = '0.75'
58-
expect(call(nil)).to eq(0.75)
58+
expect(call(nil)).to eq(1)
5959
end
6060

6161
it "does not use blank multiple" do

0 commit comments

Comments
 (0)