lib/parallel_tests/cli.rb in parallel_tests-0.10.2 vs lib/parallel_tests/cli.rb in parallel_tests-0.10.3
- old
+ new
@@ -1,6 +1,7 @@
require 'optparse'
+require 'tempfile'
module ParallelTests
class CLI
def run(argv)
options = parse_options!(argv)
@@ -15,18 +16,28 @@
end
end
private
+ def execute_in_parallel(items, num_processes, options)
+ Tempfile.open 'parallel_tests-lock' do |lock|
+ return Parallel.map(items, :in_processes => num_processes) do |item|
+ result = yield(item)
+ report_output(result, lock) if options[:serialize_stdout]
+ result
+ end
+ end
+ end
+
def run_tests_in_parallel(num_processes, options)
test_results = nil
report_time_taken do
groups = @runner.tests_in_groups(options[:files], num_processes, options)
report_number_of_tests(groups)
- test_results = Parallel.map(groups, :in_processes => groups.size) do |group|
+ test_results = execute_in_parallel(groups, groups.size, options) do |group|
run_tests(group, groups.index(group), num_processes, options)
end
report_results(test_results)
end
@@ -40,10 +51,18 @@
else
@runner.run_tests(group, process_number, num_processes, options)
end
end
+ def report_output(result, lock)
+ lock.flock File::LOCK_EX
+ $stdout.puts result[:stdout]
+ $stdout.flush
+ ensure
+ lock.flock File::LOCK_UN
+ end
+
def report_results(test_results)
results = @runner.find_results(test_results.map { |result| result[:stdout] }*"")
puts ""
puts @runner.summarize_results(results)
end
@@ -103,10 +122,11 @@
rescue NameError, LoadError => e
puts "Runner for `#{type}` type has not been found! (#{e})"
abort
end
end
+ opts.on("--serialize-stdout", "Serialize stdout output, nothing will be written until everything is done") { options[:serialize_stdout] = true }
opts.on("--non-parallel", "execute same commands but do not in parallel, needs --exec") { options[:non_parallel] = true }
opts.on("--no-symlinks", "Do not traverse symbolic links to find test files") { options[:symlinks] = false }
opts.on('--ignore-tags [PATTERN]', 'When counting steps ignore scenarios with tags that match this pattern') { |arg| options[:ignore_tag_pattern] = arg }
opts.on("-v", "--version", "Show Version") { puts ParallelTests::VERSION; exit }
opts.on("-h", "--help", "Show this.") { puts opts; exit }
@@ -131,14 +151,14 @@
def execute_shell_command_in_parallel(command, num_processes, options)
runs = (0...num_processes).to_a
results = if options[:non_parallel]
runs.map do |i|
- ParallelTests::Test::Runner.execute_command(command, i, num_processes)
+ ParallelTests::Test::Runner.execute_command(command, i, num_processes, options)
end
else
- Parallel.map(runs, :in_processes => num_processes) do |i|
- ParallelTests::Test::Runner.execute_command(command, i, num_processes)
+ execute_in_parallel(runs, num_processes, options) do |i|
+ ParallelTests::Test::Runner.execute_command(command, i, num_processes, options)
end
end.flatten
abort if results.any? { |r| r[:exit_status] != 0 }
end