test/test_poll.rb in kgio-2.3.3 vs test/test_poll.rb in kgio-2.4.0
- old
+ new
@@ -40,29 +40,54 @@
diff = Time.now - t0
assert diff >= 0.010, "diff=#{diff}"
assert_nil res
end
- def test_poll_interrupt
+ def test_poll_close
foo = nil
- oldquit = trap(:QUIT) { foo = :bar }
- thr = Thread.new { sleep 0.100; Process.kill(:QUIT, $$) }
+ thr = Thread.new { sleep 0.100; @wr.close }
t0 = Time.now
- assert_raises(Errno::EINTR) { Kgio.poll({}) }
+ res = Kgio.poll({@rd => Kgio::POLLIN})
diff = Time.now - t0
thr.join
+ assert_equal([ @rd ], res.keys)
assert diff >= 0.010, "diff=#{diff}"
+ end
+
+ def test_poll_EINTR
+ ok = false
+ orig = trap(:USR1) { ok = true }
+ thr = Thread.new do
+ sleep 0.100
+ Process.kill(:USR1, $$)
+ end
+ t0 = Time.now
+ res = Kgio.poll({@rd => Kgio::POLLIN}, 1000)
+ diff = Time.now - t0
+ thr.join
+ assert_nil res
+ assert diff >= 1.0, "diff=#{diff}"
+ assert ok
ensure
- trap(:QUIT, "DEFAULT")
+ trap(:USR1, orig)
end
- def test_poll_close
- foo = nil
- thr = Thread.new { sleep 0.100; @wr.close }
+ def test_poll_EINTR_changed
+ ok = false
+ orig = trap(:USR1) { ok = true }
+ pollset = { @rd => Kgio::POLLIN }
+ thr = Thread.new do
+ sleep 0.100
+ pollset[@wr] = Kgio::POLLOUT
+ Process.kill(:USR1, $$)
+ end
t0 = Time.now
- res = Kgio.poll({@rd => Kgio::POLLIN})
+ res = Kgio.poll(pollset, 1000)
diff = Time.now - t0
thr.join
- assert_equal([ @rd ], res.keys)
- assert diff >= 0.010, "diff=#{diff}"
+ assert_equal({@wr => Kgio::POLLOUT}, res)
+ assert diff < 1.0, "diff=#{diff}"
+ assert ok
+ ensure
+ trap(:USR1, orig)
end
end if Kgio.respond_to?(:poll)