X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fds-poll.t;h=d88613695afd42031c8251cbaa1563058562b5ea;hb=25fb42242320ffb55655d89268ddbb468eab9a6a;hp=c9dcdd22cf86607f5905cc2981785b15d14deef7;hpb=7d7e5013e3d2e56c48735698e39890e8f67b6b56;p=public-inbox.git diff --git a/t/ds-poll.t b/t/ds-poll.t index c9dcdd22..d8861369 100644 --- a/t/ds-poll.t +++ b/t/ds-poll.t @@ -1,4 +1,4 @@ -# Copyright (C) 2019 all contributors +# Copyright (C) 2019-2021 all contributors # Licensed the same as Danga::Socket (and Perl5) # License: GPL-1.0+ or Artistic-1.0-Perl # @@ -7,7 +7,7 @@ use strict; use warnings; use Test::More; use PublicInbox::Syscall qw(:epoll); -my $cls = 'PublicInbox::DSPoll'; +my $cls = $ENV{TEST_IOPOLLER} // 'PublicInbox::DSPoll'; use_ok $cls; my $p = $cls->new; @@ -16,43 +16,35 @@ pipe($r, $w) or die; pipe($x, $y) or die; is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($r), EPOLLIN), 0, 'add EPOLLIN'); my $events = []; -my $n = $p->epoll_wait(9, 0, $events); +$p->epoll_wait(9, 0, $events); is_deeply($events, [], 'no events set'); -is($n, 0, 'nothing ready, yet'); is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($w), EPOLLOUT|EPOLLONESHOT), 0, 'add EPOLLOUT|EPOLLONESHOT'); -$n = $p->epoll_wait(9, -1, $events); -is($n, 1, 'got POLLOUT event'); -is($events->[0]->[0], fileno($w), '$w ready'); +$p->epoll_wait(9, -1, $events); +is(scalar(@$events), 1, 'got POLLOUT event'); +is($events->[0], fileno($w), '$w ready'); -$n = $p->epoll_wait(9, 0, $events); -is($n, 0, 'nothing ready after oneshot'); +$p->epoll_wait(9, 0, $events); +is(scalar(@$events), 0, 'nothing ready after oneshot'); is_deeply($events, [], 'no events set after oneshot'); syswrite($w, '1') == 1 or die; for my $t (0..1) { - $n = $p->epoll_wait(9, $t, $events); - is($events->[0]->[0], fileno($r), "level-trigger POLLIN ready #$t"); - is($n, 1, "only event ready #$t"); + $p->epoll_wait(9, $t, $events); + is($events->[0], fileno($r), "level-trigger POLLIN ready #$t"); + is(scalar(@$events), 1, "only event ready #$t"); } syswrite($y, '1') == 1 or die; is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($x), EPOLLIN|EPOLLONESHOT), 0, 'EPOLLIN|EPOLLONESHOT add'); -is($p->epoll_wait(9, -1, $events), 2, 'epoll_wait has 2 ready'); -my @fds = sort(map { $_->[0] } @$events); +$p->epoll_wait(9, -1, $events); +is(scalar @$events, 2, 'epoll_wait has 2 ready'); +my @fds = sort @$events; my @exp = sort((fileno($r), fileno($x))); is_deeply(\@fds, \@exp, 'got both ready FDs'); -# EPOLL_CTL_DEL doesn't matter for kqueue, we do it in native epoll -# to avoid a kernel-wide lock; but its not needed for native kqueue -# paths so DSKQXS makes it a noop (as did Danga::Socket::close). -SKIP: { - if ($cls ne 'PublicInbox::DSPoll') { - skip "$cls doesn't handle EPOLL_CTL_DEL", 2; - } - is($p->epoll_ctl(EPOLL_CTL_DEL, fileno($r), 0), 0, 'EPOLL_CTL_DEL OK'); - $n = $p->epoll_wait(9, 0, $events); - is($n, 0, 'nothing ready after EPOLL_CTL_DEL'); -}; +is($p->epoll_ctl(EPOLL_CTL_DEL, fileno($r), 0), 0, 'EPOLL_CTL_DEL OK'); +$p->epoll_wait(9, 0, $events); +is(scalar @$events, 0, 'nothing ready after EPOLL_CTL_DEL'); done_testing;