1 require_relative 'helper'
3 class TestKqueue < Test::Unit::TestCase
8 assert_kind_of IO, kq.to_io
9 assert_predicate kq.to_io, :close_on_exec?
11 ev = Kevent[rd.fileno, EvFilt::READ, Ev::ADD|Ev::ONESHOT, 0, 0, rd]
18 n = kq.kevent(nil, 1) do |kevent|
19 assert_kind_of Kevent, kevent
22 assert_equal 1, events.size
23 assert_equal rd.fileno, events[0][0]
24 assert_equal EvFilt::READ, events[0][1]
27 # we should be drained
29 n = kq.kevent(nil, 1, 0) do |kevent|
30 assert_kind_of Kevent, kevent
33 assert_equal 0, events.size
39 ev = Kevent[wr.fileno, EvFilt::WRITE, Ev::ADD|Ev::ONESHOT, 0, 0, wr]
41 n = kq.kevent(nil, 1, 0) do |kevent|
42 assert_kind_of Kevent, kevent
45 assert_equal 1, events.size
46 assert_equal wr.fileno, events[0][0]
47 assert_equal EvFilt::WRITE, events[0][1]
55 def test_usable_after_fork
60 assert_equal(0, kq.kevent(nil, 1, 0.1) { exit!(false) })
66 assert_equal(0, kq.kevent(nil, 1, 0.1) { exit!(false) })
67 _, status = Process.waitpid2(pid)
68 assert status.success?, status.inspect
81 Kevent[r1.fileno, EvFilt::READ, Ev::ADD, 0, 0, r1],
82 Kevent[w1.fileno, EvFilt::WRITE, Ev::ADD, 0, 0, w1]
85 Kevent[r2.fileno, EvFilt::READ, Ev::ADD, 0, 0, r2],
86 Kevent[w2.fileno, EvFilt::WRITE, Ev::ADD, 0, 0, w2]
91 kq1.kevent(nil, 2) do |kev1|
93 kq2.kevent(nil, 2) do |kev2|
94 (inner[nr] ||= []) << kev2.udata
98 assert_equal [ r1, w1 ].sort_by(&:fileno), outer.sort_by(&:fileno)
99 exp = [ r2, w2 ].sort_by(&:fileno)
100 assert_equal [ exp, exp ], inner.map { |x| x.sort_by(&:fileno) }
102 [ r1, w1, r2, w2, kq1, kq2 ].compact.each(&:close)
104 end if defined?(SleepyPenguin::Kqueue)