5 class TestPoll < Test::Unit::TestCase
7 [ @rd, @wr ].each { |io| io.close unless io.closed? }
15 assert_kind_of Integer, Kgio::POLLIN
16 assert_kind_of Integer, Kgio::POLLOUT
17 assert_kind_of Integer, Kgio::POLLPRI
18 assert_kind_of Integer, Kgio::POLLHUP
19 assert_kind_of Integer, Kgio::POLLERR
20 assert_kind_of Integer, Kgio::POLLNVAL
24 set = { @rd => :wait_readable, @wr => :wait_writable }
26 assert_equal({@wr => Kgio::POLLOUT}, res)
27 assert_equal set.object_id, res.object_id
31 set = { @wr => Kgio::POLLOUT|Kgio::POLLHUP }
33 assert_equal({@wr => Kgio::POLLOUT}, res)
34 assert_equal set.object_id, res.object_id
39 res = Kgio.poll({}, 10)
41 assert diff >= 0.010, "diff=#{diff}"
47 thr = Thread.new { sleep 0.100; @wr.close }
49 res = Kgio.poll({@rd => Kgio::POLLIN})
52 assert_equal([ @rd ], res.keys)
53 assert diff >= 0.010, "diff=#{diff}"
57 orig = trap(:USR1) { @rd.close }
59 thr = Thread.new { sleep 0.100; Process.kill(:USR1, $$) }
61 assert_raises(IOError) do
62 result = Kgio.poll({@rd => Kgio::POLLIN})
63 result.each_key { |io| io.read_nonblock(1) }
67 assert diff >= 0.010, "diff=#{diff}"
74 orig = trap(:USR1) { ok = true }
77 Process.kill(:USR1, $$)
80 res = Kgio.poll({@rd => Kgio::POLLIN}, 1000)
84 assert diff >= 1.0, "diff=#{diff}"
90 def test_poll_signal_torture
94 set = { @rd => Kgio::POLLIN }
95 orig = trap(:USR1) { usr1 += 1 }
97 trap(:USR1, "DEFAULT")
100 nr.times { Process.kill(:USR1, ppid); sleep 0.05 }
105 empty += 1 until Kgio.poll(set.dup, 100)
106 _, status = Process.waitpid2(pid)
107 assert status.success?, status.inspect
108 assert usr1 > 0, "usr1: #{usr1}"
111 end unless RUBY_PLATFORM =~ /kfreebsd-gnu/
112 end if Kgio.respond_to?(:poll)