diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-04-29 19:00:39 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-04-29 21:01:01 +0000 |
commit | bb70a4e003997e6eceea0d03cd941a46ec165f82 (patch) | |
tree | 391527181b4883df6614ad95888a7b835301ee5d | |
parent | 8575d11394a84cef2a8a8bddb21ec79e8a841a59 (diff) | |
download | sleepy_penguin-bb70a4e003997e6eceea0d03cd941a46ec165f82.tar.gz |
This is not _my_ common use case, but some people may want to fetch multiple events at once.
-rw-r--r-- | test/test_kqueue_io.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/test_kqueue_io.rb b/test/test_kqueue_io.rb index ea18767..dc5f8ea 100644 --- a/test/test_kqueue_io.rb +++ b/test/test_kqueue_io.rb @@ -6,6 +6,53 @@ require 'sleepy_penguin' class TestKqueueIO < Test::Unit::TestCase include SleepyPenguin + def setup + @to_close = [] + end + + def teardown + @to_close.each do |io| + io.close unless io.closed? + end + end + + def test_multi_event + kq = Kqueue::IO.new + @to_close << kq + list = [] + pipes = [ IO.pipe, IO.pipe, IO.pipe, IO.pipe ] + pipes.each do |(r,w)| + @to_close << r + @to_close << w + list << Kevent[r.fileno, EvFilt::READ, Ev::ADD|Ev::ONESHOT, 0, 0, r] + end + kq.kevent(list) + + pipes.each do |(_,w)| + w.syswrite('.') + end + received = [] + seen = {} + kq.kevent(nil, 1) do |*args| + received << args + assert_equal 6, args.size + assert_kind_of IO, args[5] + assert_nil seen[args[5]] + seen[args[5]] = true + end + + assert_equal 1, received.size + + kq.kevent(nil, 666) do |*args| + received << args + assert_equal 6, args.size + assert_kind_of IO, args[5] + assert_nil seen[args[5]] + seen[args[5]] = true + end + assert_equal 4, received.size + end + def test_xthread kq = Kqueue::IO.new assert_kind_of IO, kq |