2003-09-04 12:18:59 -04:00
|
|
|
require 'test/unit'
|
2005-06-03 10:39:15 -04:00
|
|
|
require 'timeout'
|
2003-09-04 12:18:59 -04:00
|
|
|
|
|
|
|
class TestSignal < Test::Unit::TestCase
|
|
|
|
def test_signal
|
2003-10-19 22:31:47 -04:00
|
|
|
defined?(Process.kill) or return
|
|
|
|
begin
|
2003-09-04 12:18:59 -04:00
|
|
|
$x = 0
|
2003-10-19 22:31:47 -04:00
|
|
|
oldtrap = trap "SIGINT", proc{|sig| $x = 2}
|
2003-09-04 12:18:59 -04:00
|
|
|
Process.kill "SIGINT", $$
|
|
|
|
sleep 0.1
|
2003-09-05 11:15:43 -04:00
|
|
|
assert_equal(2, $x)
|
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
trap "SIGINT", proc{raise "Interrupt"}
|
2003-09-05 11:15:43 -04:00
|
|
|
|
|
|
|
x = assert_raises(RuntimeError) do
|
2003-09-04 12:18:59 -04:00
|
|
|
Process.kill "SIGINT", $$
|
|
|
|
sleep 0.1
|
|
|
|
end
|
2003-09-05 11:15:43 -04:00
|
|
|
assert(x)
|
|
|
|
assert_match(/Interrupt/, x.message)
|
2003-10-19 22:31:47 -04:00
|
|
|
ensure
|
|
|
|
trap "SIGINT", oldtrap
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|
|
|
|
end
|
2005-06-03 10:39:15 -04:00
|
|
|
|
|
|
|
def test_exit_action
|
|
|
|
begin
|
|
|
|
r, w = IO.pipe
|
|
|
|
pid = fork {
|
|
|
|
r0, w0 = IO.pipe
|
|
|
|
trap(:USR1, "EXIT")
|
|
|
|
Thread.start { Thread.pass }
|
|
|
|
r0.sysread(4096)
|
|
|
|
}
|
|
|
|
sleep 0.1
|
|
|
|
assert_nothing_raised("[ruby-dev:26128]") {
|
|
|
|
Process.kill(:USR1, pid)
|
|
|
|
Timeout.timeout(1) {
|
|
|
|
Process.waitpid pid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ensure
|
|
|
|
r.close
|
|
|
|
w.close
|
|
|
|
end
|
|
|
|
end
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|