Skip to content

Commit

Permalink
Ensure signaled processes at opening FIFO terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Sep 12, 2023
1 parent 39336c1 commit 385033b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/ruby/test_process.rb
Expand Up @@ -665,6 +665,7 @@ def test_execopts_redirect_open_fifo
end unless windows? # does not support fifo

def test_execopts_redirect_open_fifo_interrupt_raise
pid = nil
with_tmpchdir {|d|
begin
File.mkfifo("fifo")
Expand All @@ -682,15 +683,21 @@ class E < StandardError; end
puts "ok"
end
EOS
pid = io.pid
assert_equal("start\n", io.gets)
sleep 0.5
Process.kill(:USR1, io.pid)
assert_equal("ok\n", io.read)
}
assert_equal(pid, $?.pid)
assert_predicate($?, :success?)
}
ensure
assert_raise(Errno::ESRCH) {Process.kill(:KILL, pid)} if pid
end unless windows? # does not support fifo

def test_execopts_redirect_open_fifo_interrupt_print
pid = nil
with_tmpchdir {|d|
begin
File.mkfifo("fifo")
Expand All @@ -703,14 +710,21 @@ def test_execopts_redirect_open_fifo_interrupt_print
puts "start"
system("cat", :in => "fifo")
EOS
pid = io.pid
assert_equal("start\n", io.gets)
sleep 0.2 # wait for the child to stop at opening "fifo"
Process.kill(:USR1, io.pid)
assert_equal("trap\n", io.readpartial(8))
File.write("fifo", "ok\n")
assert_equal("ok\n", io.read)
}
assert_equal(pid, $?.pid)
assert_predicate($?, :success?)
}
ensure
if pid
assert_raise(Errno::ESRCH) {Process.kill(:KILL, pid)}
end
end unless windows? # does not support fifo

def test_execopts_redirect_pipe
Expand Down

0 comments on commit 385033b

Please sign in to comment.