Skip to content

Commit

Permalink
test_recovery_sigint: Ensure precondition is met (#829)
Browse files Browse the repository at this point in the history
* test_recovery_sigint: Ensure precondition is met

test_recovery_sigint depends on its process has SIG_DEF sigaction for
SIGINT. When its parent process set SIG_IGN which inherits to children,
then this test fails. This patch ensures this precondition met
regardless of inherited sigaction from its parent.

* Add test for restoration of other SIGINT handlers

Add another variant of test_recovery_sigint to ensure IRB to preserve
existing SIGINT handler other than SIG_DEF.
  • Loading branch information
sorah authored Jan 1, 2024
1 parent 99b0017 commit 77ee59d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/irb/test_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ def test_rc_file_in_subdir
end
end

def test_recovery_sigint
def test_sigint_restore_default
pend "This test gets stuck on Solaris for unknown reason; contribution is welcome" if RUBY_PLATFORM =~ /solaris/
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //)
# IRB should restore SIGINT handler
status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e Signal.trap("SIGINT","DEFAULT");binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //)
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
end

def test_sigint_restore_block
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
# IRB should restore SIGINT handler
status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e x=false;Signal.trap("SIGINT"){x=true};binding.irb;loop{Process.kill("SIGINT",$$);if(x);break;end} -- -f --], "exit\n", //, //)
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
end

Expand Down

0 comments on commit 77ee59d

Please sign in to comment.