From 5ed84752501d6810a9ac44d6f8167e076172a414 Mon Sep 17 00:00:00 2001 From: Jay Dorsey <191564+jaydorsey@users.noreply.github.com> Date: Sun, 31 Mar 2024 13:07:26 -0400 Subject: [PATCH] Use map_with_index --- lib/parallel_tests/cli.rb | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/parallel_tests/cli.rb b/lib/parallel_tests/cli.rb index 68896ac1..c25b6a54 100644 --- a/lib/parallel_tests/cli.rb +++ b/lib/parallel_tests/cli.rb @@ -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 @@ -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 @@ -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 }