Skip to content

Commit cfd0b91

Browse files
authored
Fix random EPIPE failure in SIGINT restore tests (#1191)
Rescue Errno::EPIPE in test_sigint_restore_default and test_sigint_restore_block. The child process may exit before assert_in_out_err finishes writing "exit\n" to its stdin pipe, which is a race condition in the test setup, not an IRB bug.
1 parent 8a1129d commit cfd0b91

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

test/irb/test_init.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@ def test_sigint_restore_default
107107
# IRB should restore SIGINT handler
108108
status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e Signal.trap("SIGINT","DEFAULT");binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //)
109109
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
110+
rescue Errno::EPIPE
111+
# The child process may exit before the parent finishes writing to stdin
110112
end
111113

112114
def test_sigint_restore_block
113115
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
114116
# IRB should restore SIGINT handler
115117
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", //, //)
116118
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
119+
rescue Errno::EPIPE
120+
# The child process may exit before the parent finishes writing to stdin
117121
end
118122

119123
def test_no_color_environment_variable

0 commit comments

Comments
 (0)