about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-01 09:54:41 +0000
committerEric Wong <e@80x24.org>2021-10-01 12:06:31 +0000
commit1c52f49354aa83e71fcceccae888da0c77f2391d (patch)
treebd6eabaed8cc0376e4a56cb6ec34cf962fd7ffdb /t
parent5824d0d4ffac120a2840c980b4570868d6b3ea6b (diff)
downloadpublic-inbox-1c52f49354aa83e71fcceccae888da0c77f2391d.tar.gz
Since signalfd is often combined with our event loop, give it a
convenient API and reduce the code duplication required to use it.

EventLoop is replaced with ::event_loop to allow consistent
parameter passing and avoid needlessly passing the package name
on stack.

We also avoid exporting SFD_NONBLOCK since it's the only flag we
support.  There's no sense in having the memory overhead of a
constant function when it's in cold code.
Diffstat (limited to 't')
-rw-r--r--t/dir_idle.t6
-rw-r--r--t/ds-leak.t4
-rw-r--r--t/imapd.t6
-rw-r--r--t/nntpd.t2
-rw-r--r--t/sigfd.t7
-rw-r--r--t/watch_maildir.t2
6 files changed, 13 insertions, 14 deletions
diff --git a/t/dir_idle.t b/t/dir_idle.t
index 0bb3b758..8e7f3b70 100644
--- a/t/dir_idle.t
+++ b/t/dir_idle.t
@@ -15,7 +15,7 @@ my $end = 3 + now;
 PublicInbox::DS->SetPostLoopCallback(sub { scalar(@x) == 0 && now < $end });
 tick(0.011);
 rmdir("$tmpdir/a/b") or xbail "rmdir $!";
-PublicInbox::DS->EventLoop;
+PublicInbox::DS::event_loop();
 is(scalar(@x), 1, 'got an event') and
         is($x[0]->[0]->fullname, "$tmpdir/a/b", 'got expected fullname') and
         ok($x[0]->[0]->IN_DELETE, 'IN_DELETE set');
@@ -24,7 +24,7 @@ tick(0.011);
 rmdir("$tmpdir/a") or xbail "rmdir $!";
 @x = ();
 $end = 3 + now;
-PublicInbox::DS->EventLoop;
+PublicInbox::DS::event_loop();
 is(scalar(@x), 1, 'got an event') and
         is($x[0]->[0]->fullname, "$tmpdir/a", 'got expected fullname') and
         ok($x[0]->[0]->IN_DELETE_SELF, 'IN_DELETE_SELF set');
@@ -33,7 +33,7 @@ tick(0.011);
 rename("$tmpdir/c", "$tmpdir/j") or xbail "rmdir $!";
 @x = ();
 $end = 3 + now;
-PublicInbox::DS->EventLoop;
+PublicInbox::DS::event_loop();
 is(scalar(@x), 1, 'got an event') and
         is($x[0]->[0]->fullname, "$tmpdir/c", 'got expected fullname') and
         ok($x[0]->[0]->IN_DELETE_SELF || $x[0]->[0]->IN_MOVE_SELF,
diff --git a/t/ds-leak.t b/t/ds-leak.t
index 4c211639..4e8d76cd 100644
--- a/t/ds-leak.t
+++ b/t/ds-leak.t
@@ -19,7 +19,7 @@ if ('close-on-exec for epoll and kqueue') {
         pipe($r, $w) or die "pipe: $!";
 
         PublicInbox::DS::add_timer(0, sub { $pid = spawn([qw(sleep 10)]) });
-        PublicInbox::DS->EventLoop;
+        PublicInbox::DS::event_loop();
         ok($pid, 'subprocess spawned');
 
         # wait for execve, we need to ensure lsof sees sleep(1)
@@ -56,7 +56,7 @@ SKIP: {
         for my $i (0..$n) {
                 PublicInbox::DS->SetLoopTimeout(0);
                 PublicInbox::DS->SetPostLoopCallback($cb);
-                PublicInbox::DS->EventLoop;
+                PublicInbox::DS::event_loop();
                 PublicInbox::DS->Reset;
         }
         ok(1, "Reset works and doesn't hit RLIMIT_NOFILE ($n)");
diff --git a/t/imapd.t b/t/imapd.t
index bd8ad7e5..80757a9d 100644
--- a/t/imapd.t
+++ b/t/imapd.t
@@ -466,7 +466,7 @@ SKIP: {
         my $w = start_script(['-watch'], undef, { 2 => $err_wr });
 
         diag 'waiting for initial fetch...';
-        PublicInbox::DS->EventLoop;
+        PublicInbox::DS::event_loop();
         diag 'inbox unlocked on initial fetch, waiting for IDLE';
 
         tick until (grep(/I: \S+ idling/, <$err>));
@@ -477,7 +477,7 @@ SKIP: {
                 diag "mda error \$?=$?";
         diag 'waiting for IMAP IDLE wakeup';
         PublicInbox::DS->SetPostLoopCallback(undef);
-        PublicInbox::DS->EventLoop;
+        PublicInbox::DS::event_loop();
         diag 'inbox unlocked on IDLE wakeup';
 
         # try again with polling
@@ -494,7 +494,7 @@ SKIP: {
 
         diag 'waiting for PollInterval wakeup';
         PublicInbox::DS->SetPostLoopCallback(undef);
-        PublicInbox::DS->EventLoop;
+        PublicInbox::DS::event_loop();
         diag 'inbox unlocked (poll)';
         $w->kill;
         $w->join;
diff --git a/t/nntpd.t b/t/nntpd.t
index 3c171a3b..cf1c44f8 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -439,7 +439,7 @@ sub test_watch {
         my $w = start_script(['-watch'], undef, { 2 => $err_wr });
 
         diag 'waiting for initial fetch...';
-        PublicInbox::DS->EventLoop;
+        PublicInbox::DS::event_loop();
         diag 'inbox unlocked on initial fetch';
         $w->kill;
         $w->join;
diff --git a/t/sigfd.t b/t/sigfd.t
index a1ab222c..a68b12a6 100644
--- a/t/sigfd.t
+++ b/t/sigfd.t
@@ -4,7 +4,6 @@ use Test::More;
 use IO::Handle;
 use POSIX qw(:signal_h);
 use Errno qw(ENOSYS);
-use PublicInbox::Syscall qw(SFD_NONBLOCK);
 require_ok 'PublicInbox::Sigfd';
 use PublicInbox::DS;
 
@@ -40,18 +39,18 @@ SKIP: {
                 }
                 $sigfd = undef;
 
-                my $nbsig = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
+                my $nbsig = PublicInbox::Sigfd->new($sig, 1);
                 ok($nbsig, 'Sigfd->new SFD_NONBLOCK works');
                 is($nbsig->wait_once, undef, 'nonblocking ->wait_once');
                 ok($! == Errno::EAGAIN, 'got EAGAIN');
                 kill('HUP', $$) or die "kill $!";
                 PublicInbox::DS->SetPostLoopCallback(sub {}); # loop once
-                PublicInbox::DS->EventLoop;
+                PublicInbox::DS::event_loop();
                 is($hit->{HUP}->{sigfd}, 2, 'HUP sigfd fired in event loop') or
                         diag explain($hit); # sometimes fails on FreeBSD 11.x
                 kill('TERM', $$) or die "kill $!";
                 kill('HUP', $$) or die "kill $!";
-                PublicInbox::DS->EventLoop;
+                PublicInbox::DS::event_loop();
                 PublicInbox::DS->Reset;
                 is($hit->{TERM}->{sigfd}, 1, 'TERM sigfd fired in event loop');
                 is($hit->{HUP}->{sigfd}, 3, 'HUP sigfd fired in event loop');
diff --git a/t/watch_maildir.t b/t/watch_maildir.t
index e74b512f..6399fb7c 100644
--- a/t/watch_maildir.t
+++ b/t/watch_maildir.t
@@ -199,7 +199,7 @@ More majordomo info at  http://vger.kernel.org/majordomo-info.html\n);
 
         $em->commit; # wake -watch up
         diag 'waiting for -watch to import new message';
-        PublicInbox::DS->EventLoop;
+        PublicInbox::DS::event_loop();
         $wm->kill;
         $wm->join;
         $ii->close;