Skip to content

Commit

Permalink
Use map_with_index
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydorsey committed Mar 31, 2024
1 parent 470801e commit 5ed8475
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions lib/parallel_tests/cli.rb
Expand Up @@ -57,8 +57,8 @@ def execute_in_parallel(items, num_processes, options)
Tempfile.open 'parallel_tests-lock' do |lock|
ParallelTests.with_pid_file do
simulate_output_for_ci options[:serialize_stdout] do
Parallel.map(items, in_threads: num_processes) do |item|
result = yield(item)
Parallel.map_with_index(items, in_threads: num_processes) do |item, index|
result = yield(item, index)
reprint_output(result, lock.path) if options[:serialize_stdout]
ParallelTests.stop_all_processes if options[:fail_fast] && result[:exit_status] != 0
result
Expand All @@ -81,9 +81,9 @@ def run_tests_in_parallel(num_processes, options)
end

report_number_of_tests(groups) unless options[:quiet]
test_results = execute_in_parallel(groups, groups.size, options) do |group|
test_env = env_index(options).call(groups, group)
run_tests(group, test_env, num_processes, options)
test_results = execute_in_parallel(groups, groups.size, options) do |group, index|
test_env_number = options[:first_is_1] ? index + 1 : index
run_tests(group, test_env_number, num_processes, options)
end
report_results(test_results, options) unless options[:quiet]
end
Expand All @@ -108,19 +108,6 @@ def run_tests_in_parallel(num_processes, options)
end
end

def env_index(options)
return @env_index if defined?(@env_index)

start = options[:first_is_1] ? 0 : -1

@env_index =
if options[:allow_duplicates]
proc { start += 1 }
else
->(groups, group) { groups.index(group) }
end
end

def run_tests(group, process_number, num_processes, options)
if group.empty?
{ stdout: '', exit_status: 0, command: nil, seed: nil }
Expand Down

0 comments on commit 5ed8475

Please sign in to comment.