diff options
author | Eric Wong <e@yhbt.net> | 2020-06-27 10:03:36 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-06-28 22:27:14 +0000 |
commit | b2b1006759730507731fcd3fc3e0de68239e3b92 (patch) | |
tree | e29d5c29682b05a5d87b9db1452dda92bde6a0d2 /t | |
parent | 5808636263d72b635a46100a7e7037074dad8f75 (diff) | |
download | public-inbox-b2b1006759730507731fcd3fc3e0de68239e3b92.tar.gz |
Since we already use inotify and EVFILT_VNODE (kqueue) in -imapd, we might as well use them directly in -watch, too. This will allow public-inbox-watch to use PublicInbox::DS for timers to watch newsgroups/mailboxes and have saner signal handling in future commits.
Diffstat (limited to 't')
-rw-r--r-- | t/dir_idle.t | 6 | ||||
-rw-r--r-- | t/imapd.t | 6 | ||||
-rw-r--r-- | t/watch_filter_rubylang.t | 2 | ||||
-rw-r--r-- | t/watch_maildir.t | 85 | ||||
-rw-r--r-- | t/watch_maildir_v2.t | 2 | ||||
-rw-r--r-- | t/watch_multiple_headers.t | 2 |
6 files changed, 88 insertions, 15 deletions
diff --git a/t/dir_idle.t b/t/dir_idle.t new file mode 100644 index 00000000..587599e8 --- /dev/null +++ b/t/dir_idle.t @@ -0,0 +1,6 @@ +#!perl -w +# Copyright (C) 2020 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +use Test::More; +use_ok 'PublicInbox::DirIdle'; +done_testing; @@ -462,7 +462,7 @@ ok($mic->logout, 'logged out'); PublicInbox::DS->Reset; my $ii = PublicInbox::InboxIdle->new($cfg); my $cb = sub { PublicInbox::DS->SetPostLoopCallback(sub {}) }; - my $obj = bless \$cb, 'InboxWakeup'; + my $obj = bless \$cb, 'PublicInbox::TestCommon::InboxWakeup'; $cfg->each_inbox(sub { $_[0]->subscribe_unlock('ident', $obj) }); open my $err, '+>', undef or BAIL_OUT $!; my $w = start_script(['-watch'], undef, { 2 => $err }); @@ -488,7 +488,3 @@ unlike($eout, qr/wide/i, 'no Wide character warnings'); unlike($eout, qr/uninitialized/i, 'no uninitialized warnings'); done_testing; - -package InboxWakeup; -use strict; -sub on_inbox_unlock { ${$_[0]}->() } diff --git a/t/watch_filter_rubylang.t b/t/watch_filter_rubylang.t index 2e7d402e..db48cb2f 100644 --- a/t/watch_filter_rubylang.t +++ b/t/watch_filter_rubylang.t @@ -6,7 +6,7 @@ use PublicInbox::TestCommon; use Test::More; use PublicInbox::Eml; use PublicInbox::Config; -require_mods(qw(Filesys::Notify::Simple DBD::SQLite Search::Xapian)); +require_mods(qw(DBD::SQLite Search::Xapian)); use_ok 'PublicInbox::WatchMaildir'; use_ok 'PublicInbox::Emergency'; my ($tmpdir, $for_destroy) = tmpdir(); diff --git a/t/watch_maildir.t b/t/watch_maildir.t index 33a3458b..a2c09b03 100644 --- a/t/watch_maildir.t +++ b/t/watch_maildir.t @@ -7,7 +7,6 @@ use Cwd; use PublicInbox::Config; use PublicInbox::TestCommon; use PublicInbox::Import; -require_mods(qw(Filesys::Notify::Simple)); my ($tmpdir, $for_destroy) = tmpdir(); my $git_dir = "$tmpdir/test.git"; my $maildir = "$tmpdir/md"; @@ -47,14 +46,22 @@ EOF 'only got the spam folder to watch'); } -my $config = PublicInbox::Config->new(\<<EOF); -$cfgpfx.address=$addr -$cfgpfx.inboxdir=$git_dir -$cfgpfx.watch=maildir:$maildir -$cfgpfx.filter=PublicInbox::Filter::Vger -publicinboxlearn.watchspam=maildir:$spamdir +my $cfg_path = "$tmpdir/config"; +{ + open my $fh, '>', $cfg_path or BAIL_OUT $!; + print $fh <<EOF or BAIL_OUT $!; +[publicinbox "test"] + address = $addr + inboxdir = $git_dir + watch = maildir:$maildir + filter = PublicInbox::Filter::Vger +[publicinboxlearn] + watchspam = maildir:$spamdir EOF + close $fh or BAIL_OUT $!; +} +my $config = PublicInbox::Config->new($cfg_path); PublicInbox::WatchMaildir->new($config)->scan('full'); my $git = PublicInbox::Git->new($git_dir); my @list = $git->qx(qw(rev-list refs/heads/master)); @@ -136,6 +143,70 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); like($$mref, qr/something\n\z/s, 'message scrubbed on import'); } +# end-to-end test which actually uses inotify/kevent +{ + my $env = { PI_CONFIG => $cfg_path }; + $git->cleanup; + + # n.b. --no-scan is only intended for testing atm + my $wm = start_script([qw(-watch --no-scan)], $env); + my $eml = eml_load('t/data/0001.patch'); + $eml->header_set('Cc', $addr); + my $em = PublicInbox::Emergency->new($maildir); + $em->prepare(\($eml->as_string)); + + use_ok 'PublicInbox::InboxIdle'; + use_ok 'PublicInbox::DS'; + my $delivered = 0; + my $cb = sub { + my ($ibx) = @_; + diag "message delivered to `$ibx->{name}'"; + $delivered++; + }; + PublicInbox::DS->Reset; + my $ii = PublicInbox::InboxIdle->new($config); + my $obj = bless \$cb, 'PublicInbox::TestCommon::InboxWakeup'; + $config->each_inbox(sub { $_[0]->subscribe_unlock('ident', $obj) }); + PublicInbox::DS->SetPostLoopCallback(sub { $delivered == 0 }); + + # wait for -watch to setup inotify watches + my $sleep = 1; + if (eval { require Linux::Inotify2 } && -d "/proc/$wm->{pid}/fd") { + my $end = time + 2; + my (@ino, @ino_info); + do { + @ino = grep { + (readlink($_)//'') =~ /\binotify\b/ + } glob("/proc/$wm->{pid}/fd/*"); + } until (@ino || time > $end || !tick); + if (scalar(@ino) == 1) { + my $ino_fd = (split('/', $ino[0]))[-1]; + my $ino_fdinfo = "/proc/$wm->{pid}/fdinfo/$ino_fd"; + while (time < $end && open(my $fh, '<', $ino_fdinfo)) { + @ino_info = grep(/^inotify wd:/, <$fh>); + last if @ino_info >= 4; + tick; + } + $sleep = undef if @ino_info >= 4; + } + } + if ($sleep) { + diag "waiting ${sleep}s for -watch to start up"; + sleep $sleep; + } + + $em->commit; # wake -watch up + diag 'waiting for -watch to import new message'; + PublicInbox::DS->EventLoop; + $wm->kill; + $wm->join; + $ii->close; + PublicInbox::DS->Reset; + my $head = $git->qx(qw(cat-file commit HEAD)); + my $subj = $eml->header('Subject'); + like($head, qr/^\Q$subj\E/sm, 'new commit made'); +} + sub is_maildir { my ($dir) = @_; PublicInbox::WatchMaildir::is_maildir($dir); diff --git a/t/watch_maildir_v2.t b/t/watch_maildir_v2.t index 19a2da77..6cc8b6ff 100644 --- a/t/watch_maildir_v2.t +++ b/t/watch_maildir_v2.t @@ -8,7 +8,7 @@ use PublicInbox::Config; use PublicInbox::TestCommon; use PublicInbox::Import; require_git(2.6); -require_mods(qw(Search::Xapian DBD::SQLite Filesys::Notify::Simple)); +require_mods(qw(Search::Xapian DBD::SQLite)); require PublicInbox::V2Writable; my ($tmpdir, $for_destroy) = tmpdir(); my $inboxdir = "$tmpdir/v2"; diff --git a/t/watch_multiple_headers.t b/t/watch_multiple_headers.t index 3a39eba9..0ee96d5f 100644 --- a/t/watch_multiple_headers.t +++ b/t/watch_multiple_headers.t @@ -5,7 +5,7 @@ use Test::More; use PublicInbox::Config; use PublicInbox::TestCommon; require_git(2.6); -require_mods(qw(Search::Xapian DBD::SQLite Filesys::Notify::Simple)); +require_mods(qw(Search::Xapian DBD::SQLite)); my ($tmpdir, $for_destroy) = tmpdir(); my $inboxdir = "$tmpdir/v2"; my $maildir = "$tmpdir/md"; |