From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: normalperson@yhbt.net Received: from zedshaw2.xen.prgmr.com (zedshaw2.xen.prgmr.com [71.19.156.177]) by dcvr.yhbt.net (Postfix) with ESMTP id 1F1871F5BD for ; Tue, 30 Apr 2013 02:40:08 +0000 (UTC) Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 58DB973DEE for ; Tue, 30 Apr 2013 02:42:05 +0000 (UTC) MIME-Version: 1.0 Date: Tue, 30 Apr 2013 02:39:31 +0000 From: Eric Wong List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Message-Id: <1367289582-31293-7-git-send-email-normalperson@yhbt.net> Precedence: list References: <1367289582-31293-1-git-send-email-normalperson@yhbt.net> Sender: sleepy.penguin@librelist.org Subject: [sleepy.penguin] [PATCH 06/17] test_kqueue_io: test for multiple event return To: sleepy.penguin@librelist.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This is not _my_ common use case, but some people may want to fetch multiple events at once. --- test/test_kqueue_io.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) 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 @@ 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 -- 1.8.2.1.367.gc875ca7