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

Rajaramaniyer master #982

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/parallel_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def parse_options!(argv)
opts.on("--unknown-runtime [FLOAT]", Float, "Use given number as unknown runtime (otherwise use average time)") { |time| options[:unknown_runtime] = time }
opts.on("--first-is-1", "Use \"1\" as TEST_ENV_NUMBER to not reuse the default test environment") { options[:first_is_1] = true }
opts.on("--fail-fast", "Stop all groups when one group fails (best used with --test-options '--fail-fast' if supported") { options[:fail_fast] = true }
opts.on("--cmd-length-limit", Integer, "Limit commands to this length by batching files that are being tested (use 8192 for windows)") { |limit| options[:cmd_length_limit] = limit }
opts.on("--verbose", "Print debug output") { options[:verbose] = true }
opts.on("--verbose-command", "Combines options --verbose-process-command and --verbose-rerun-command") { options.merge! verbose_process_command: true, verbose_rerun_command: true }
opts.on("--verbose-process-command", "Print the command that will be executed by each process before it begins") { options[:verbose_process_command] = true }
Expand Down
37 changes: 36 additions & 1 deletion lib/parallel_tests/test/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ def tests_with_size(tests, options)
tests
end

def split_command_into_batches(cmd, limit, test_folders)
raise "only testing a single folder is supported when splitting into batches" if test_folders.size != 1
tests, base = cmd.partition { |arg| arg.start_with?(test_folders.first) }

batches = []
batch = base.dup # first batch
tests.each do |file|
if (batch + [file]).shelljoin.size > limit
batches << batch
batch = base.dup
end
batch << file
end
batches << batch # last batch
batches
end

def combine_batch_results(results)
result = results[0]
results[1..].each do |res|
result[:stdout] = result[:stdout].to_s + res[:stdout].to_s
result[:exit_status] = [res[:exit_status], result[:exit_status]].max
# adding all files back in, not using original cmd to show what was actually run
result[:command] |= res[:command]
end
result
end

def execute_command(cmd, process_number, num_processes, options)
number = test_env_number(process_number, options).to_s
env = (options[:env] || {}).merge(
Expand All @@ -99,7 +127,14 @@ def execute_command(cmd, process_number, num_processes, options)

print_command(cmd, env) if report_process_command?(options) && !options[:serialize_stdout]

execute_command_and_capture_output(env, cmd, options)
if (limit = options[:cmd_length_limit])
results = split_command_into_batches(cmd, limit, options[:files]).map do |subcmd|
execute_command_and_capture_output(env, subcmd, options)
end
combine_batch_results(results)
else
execute_command_and_capture_output(env, cmd, options)
end
end

def print_command(command, env)
Expand Down
Loading