lib/parallel_tests/cli.rb in parallel_tests-1.3.8 vs lib/parallel_tests/cli.rb in parallel_tests-1.3.9
- old
+ new
@@ -21,11 +21,11 @@
def execute_in_parallel(items, num_processes, options)
Tempfile.open 'parallel_tests-lock' do |lock|
return Parallel.map(items, :in_threads => num_processes) do |item|
result = yield(item)
- report_output(result, lock) if options[:serialize_stdout]
+ reprint_output(result, lock.path) if options[:serialize_stdout]
result
end
end
end
@@ -61,14 +61,25 @@
else
@runner.run_tests(group, process_number, num_processes, options)
end
end
- def report_output(result, lock)
- File.open(lock.path) do |open_lock|
- open_lock.flock File::LOCK_EX
+ def reprint_output(result, lockfile)
+ lock(lockfile) do
$stdout.puts result[:stdout]
$stdout.flush
+ end
+ end
+
+ def lock(lockfile)
+ File.open(lockfile) do |lock|
+ begin
+ lock.flock File::LOCK_EX
+ yield
+ ensure
+ # This shouldn't be necessary, but appears to be
+ lock.flock File::LOCK_UN
+ end
end
end
def report_results(test_results)
results = @runner.find_results(test_results.map { |result| result[:stdout] }*"")