Skip to content

Commit 77ee59d

Browse files
authored
test_recovery_sigint: Ensure precondition is met (#829)
* 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.
1 parent 99b0017 commit 77ee59d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/irb/test_init.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,18 @@ def test_rc_file_in_subdir
6666
end
6767
end
6868

69-
def test_recovery_sigint
69+
def test_sigint_restore_default
7070
pend "This test gets stuck on Solaris for unknown reason; contribution is welcome" if RUBY_PLATFORM =~ /solaris/
7171
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
72-
status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //)
72+
# IRB should restore SIGINT handler
73+
status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e Signal.trap("SIGINT","DEFAULT");binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //)
74+
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
75+
end
76+
77+
def test_sigint_restore_block
78+
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
79+
# IRB should restore SIGINT handler
80+
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", //, //)
7381
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
7482
end
7583

0 commit comments

Comments
 (0)