Skip to content

Commit

Permalink
fix double int without breaking stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Feb 4, 2023
1 parent b0d2e56 commit 53ecbed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
5 changes: 0 additions & 5 deletions lib/parallel_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ def run(argv)
def handle_interrupt
@graceful_shutdown_attempted ||= false
Kernel.exit if @graceful_shutdown_attempted

# The Pid class's synchronize method can't be called directly from a trap
# Using Thread workaround https://github.com/ddollar/foreman/issues/332
Thread.new { ParallelTests.stop_all_processes }

@graceful_shutdown_attempted = true
end

Expand Down
5 changes: 2 additions & 3 deletions lib/parallel_tests/test/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ def print_command(command, env)
end

def execute_command_and_capture_output(env, cmd, options)
pid = nil

popen_options = { pgroup: true }
popen_options = {} # do not add `pgroup: true`, it will break `binding.irb` inside the test
popen_options[:err] = [:child, :out] if options[:combine_stderr]

pid = nil
output = IO.popen(env, cmd, popen_options) do |io|
pid = io.pid
ParallelTests.pids.add(pid)
Expand Down
26 changes: 15 additions & 11 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,18 +664,22 @@ class A < Spinach::FeatureSteps
end

describe "graceful shutdown" do
# TODO: this fail in the test but works when executed via console (each sub-process gets a INT signal when hitting Ctrl+C)
# Process.kill on Windows doesn't work as expected. It kills all process group instead of just one process.
it "passes on int signal to child processes", unless: Gem.win_platform? do
timeout = 2
write "spec/test_spec.rb", "sleep #{timeout}; describe { specify { 'Should not get here' }; specify { p 'Should not get here either'} }"
pid = nil
Thread.new { sleep timeout - 0.5; Process.kill("INT", pid) }
result = run_tests(["spec"], processes: 2, type: 'rspec', fail: true) { |io| pid = io.pid }

expect(result).to include("RSpec is shutting down")
expect(result).to_not include("Should not get here")
expect(result).to_not include("Should not get here either")
end
# it "passes on int signal to child processes", unless: Gem.win_platform? do
# timeout = 2
# write(
# "spec/test_spec.rb",
# "sleep #{timeout}; describe { specify { p 'Should not get here' }; specify { p 'Should not get here either'} }"
# )
# pid = nil
# Thread.new { sleep timeout - 0.5; Process.kill("INT", pid) }
# result = run_tests(["spec"], processes: 2, type: 'rspec', fail: true) { |io| pid = io.pid }
#
# expect(result).to include("RSpec is shutting down")
# expect(result).to_not include("Should not get here")
# expect(result).to_not include("Should not get here either")
# end

# Process.kill on Windows doesn't work as expected. It kills all process group instead of just one process.
it "exits immediately if another int signal is received", unless: Gem.win_platform? do
Expand Down

0 comments on commit 53ecbed

Please sign in to comment.