user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH] ds: cleanup poll test and avoid clobbering imports
@ 2019-06-26  8:05 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2019-06-26  8:05 UTC (permalink / raw)
  To: meta

On Linux systems with epoll support, we don't want to be
clobbering defined subs in the t/ds-poll.t test; so use
OO ->method dispatch instead and require users to explicitly
import subs via EXPORT_OK.
---
 lib/PublicInbox/DS.pm     |  2 +-
 lib/PublicInbox/DSKQXS.pm |  2 +-
 lib/PublicInbox/DSPoll.pm |  2 +-
 t/ds-poll.t               | 20 ++++++++++----------
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 08f4e9e8..a8700bc5 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -151,7 +151,7 @@ sub _InitPoller
             $cls = "PublicInbox::$_";
             last if eval "require $cls";
         }
-        $cls->import;
+        $cls->import(qw(epoll_ctl epoll_wait));
         $Epoll = $cls->new;
     }
     *EventLoop = *EpollEventLoop;
diff --git a/lib/PublicInbox/DSKQXS.pm b/lib/PublicInbox/DSKQXS.pm
index 38e13446..364df3d6 100644
--- a/lib/PublicInbox/DSKQXS.pm
+++ b/lib/PublicInbox/DSKQXS.pm
@@ -17,7 +17,7 @@ use parent qw(IO::KQueue);
 use parent qw(Exporter);
 use IO::KQueue;
 use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT EPOLL_CTL_DEL);
-our @EXPORT = qw(epoll_ctl epoll_wait);
+our @EXPORT_OK = qw(epoll_ctl epoll_wait);
 my $owner_pid = -1; # kqueue is close-on-fork (yes, fork, not exec)
 
 # map EPOLL* bits to kqueue EV_* flags for EV_SET
diff --git a/lib/PublicInbox/DSPoll.pm b/lib/PublicInbox/DSPoll.pm
index e65640a8..ce7c2fac 100644
--- a/lib/PublicInbox/DSPoll.pm
+++ b/lib/PublicInbox/DSPoll.pm
@@ -14,7 +14,7 @@ use warnings;
 use parent qw(Exporter);
 use IO::Poll;
 use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT EPOLL_CTL_DEL);
-our @EXPORT = qw(epoll_ctl epoll_wait);
+our @EXPORT_OK = qw(epoll_ctl epoll_wait);
 
 sub new { bless {}, $_[0] } # fd => events
 
diff --git a/t/ds-poll.t b/t/ds-poll.t
index a397ee06..c9dcdd22 100644
--- a/t/ds-poll.t
+++ b/t/ds-poll.t
@@ -14,31 +14,31 @@ my $p = $cls->new;
 my ($r, $w, $x, $y);
 pipe($r, $w) or die;
 pipe($x, $y) or die;
-is(epoll_ctl($p, EPOLL_CTL_ADD, fileno($r), EPOLLIN), 0, 'add EPOLLIN');
+is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($r), EPOLLIN), 0, 'add EPOLLIN');
 my $events = [];
-my $n = epoll_wait($p, 9, 0, $events);
+my $n = $p->epoll_wait(9, 0, $events);
 is_deeply($events, [], 'no events set');
 is($n, 0, 'nothing ready, yet');
-is(epoll_ctl($p, EPOLL_CTL_ADD, fileno($w), EPOLLOUT|EPOLLONESHOT), 0,
+is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($w), EPOLLOUT|EPOLLONESHOT), 0,
 	'add EPOLLOUT|EPOLLONESHOT');
-$n = epoll_wait($p, 9, -1, $events);
+$n = $p->epoll_wait(9, -1, $events);
 is($n, 1, 'got POLLOUT event');
 is($events->[0]->[0], fileno($w), '$w ready');
 
-$n = epoll_wait($p, 9, 0, $events);
+$n = $p->epoll_wait(9, 0, $events);
 is($n, 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 = epoll_wait($p, 9, $t, $events);
+	$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");
 }
 syswrite($y, '1') == 1 or die;
-is(epoll_ctl($p, EPOLL_CTL_ADD, fileno($x), EPOLLIN|EPOLLONESHOT), 0,
+is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($x), EPOLLIN|EPOLLONESHOT), 0,
 	'EPOLLIN|EPOLLONESHOT add');
-is(epoll_wait($p, 9, -1, $events), 2, 'epoll_wait has 2 ready');
+is($p->epoll_wait(9, -1, $events), 2, 'epoll_wait has 2 ready');
 my @fds = sort(map { $_->[0] } @$events);
 my @exp = sort((fileno($r), fileno($x)));
 is_deeply(\@fds, \@exp, 'got both ready FDs');
@@ -50,8 +50,8 @@ SKIP: {
 	if ($cls ne 'PublicInbox::DSPoll') {
 		skip "$cls doesn't handle EPOLL_CTL_DEL", 2;
 	}
-	is(epoll_ctl($p, EPOLL_CTL_DEL, fileno($r), 0), 0, 'EPOLL_CTL_DEL OK');
-	$n = epoll_wait($p, 9, 0, $events);
+	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');
 };
 
-- 
EW


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-26  8:05 [PATCH] ds: cleanup poll test and avoid clobbering imports Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox