From 77ee59d026d68b450578c50ec6e6d00056927113 Mon Sep 17 00:00:00 2001 From: Sorah Fukumori Date: Mon, 1 Jan 2024 19:58:32 +0900 Subject: [PATCH] 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. --- test/irb/test_init.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index 7d11b5b50..036509813 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -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