Skip to content

Commit

Permalink
Add serialize-stdout heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonah Hirsch committed Jul 12, 2016
1 parent 40ef1bd commit dfe460c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/parallel_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ def run(argv)

def execute_in_parallel(items, num_processes, options)
Tempfile.open 'parallel_tests-lock' do |lock|
# CI systems often fail when there is no output for a long time, so simulate some output
progress_indicator = Thread.new { while true do sleep ENV.fetch('PARALLEL_TEST_HEARTBEAT_INTERVAL', 60).to_f; print '.' end } if options[:serialize_stdout]
return Parallel.map(items, :in_threads => num_processes) do |item|
result = yield(item)
if progress_indicator && progress_indicator.alive?
progress_indicator.exit
puts
end
reprint_output(result, lock.path) if options[:serialize_stdout]
result
end
Expand Down
7 changes: 7 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ def test_unicode
expect(result).not_to match(/TEST2.*TEST1.*TEST2/m)
end

it "can show simulated output when serializing stdout" do
write 'spec/xxx_spec.rb', 'describe("it"){it("should"){sleep 1; puts "TEST1"}}'
result = run_tests "spec", :type => 'rspec', :add => "--serialize-stdout", export: 'PARALLEL_TEST_HEARTBEAT_INTERVAL=0.2'

expect(result).to match(/\.{5}.*TEST1/m)
end

it "can serialize stdout and stderr" do
write 'spec/xxx_spec.rb', '5.times{describe("it"){it("should"){sleep 0.01; $stderr.puts "errTEST1"; puts "TEST1"}}}'
write 'spec/xxx2_spec.rb', 'sleep 0.01; 5.times{describe("it"){it("should"){sleep 0.01; $stderr.puts "errTEST2"; puts "TEST2"}}}'
Expand Down

0 comments on commit dfe460c

Please sign in to comment.