about summary refs log tree commit homepage
path: root/t/lei-auto-watch.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-02 10:17:58 +0000
committerEric Wong <e@80x24.org>2021-09-02 21:22:50 +0000
commit4166c482b710acea785063de2c69a8a370c6d373 (patch)
treeb6dfb983908d485b66f6e6140b45f71a6fcae251 /t/lei-auto-watch.t
parent4f9c44e3fff9c413fc54050dcc633692d33f6968 (diff)
downloadpublic-inbox-4166c482b710acea785063de2c69a8a370c6d373.tar.gz
This works with existing inotify/EVFILT_VNODE functionality to
propagate changes made from one Maildir to another Maildir.

I chose the lei/store worker process to handle this since
propagating changes back into lei-daemon on a massive scale
could lead to dead-locking while both processes are attempting
to write to each other.  Eliminating IPC overhead is a nice
side effect, but could hurt performance if Maildirs are slow.

The code for "lei export-kw" is significantly revamped to match
the new code used in the "lei/store" daemon.  It should be more
correct w.r.t. corner-cases and stale entries, but perhaps
better tests need to be written.

squashed:
  t/lei-auto-watch: increase delay for FreeBSD kevent

  My FreeBSD VM seems to need longer for this test than inotify
  under Linux, likely because the kevent support code needs to be
  more complicated.
Diffstat (limited to 't/lei-auto-watch.t')
-rw-r--r--t/lei-auto-watch.t45
1 files changed, 45 insertions, 0 deletions
diff --git a/t/lei-auto-watch.t b/t/lei-auto-watch.t
new file mode 100644
index 00000000..146402a6
--- /dev/null
+++ b/t/lei-auto-watch.t
@@ -0,0 +1,45 @@
+#!perl -w
+# Copyright all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict; use v5.10.1; use PublicInbox::TestCommon;
+use File::Basename qw(basename);
+my ($ro_home, $cfg_path) = setup_public_inboxes;
+my $tick = 2.1;
+my $have_fast_inotify = eval { require Linux::Inotify2; $tick = 0.1 } ||
+        eval { require IO::KQueue; $tick = 0.5 };
+
+$have_fast_inotify or
+        diag("$0 IO::KQueue or Linux::Inotify2 missing, test will be slow");
+
+test_lei(sub {
+        my $x = "$ENV{HOME}/x";
+        my $y = "$ENV{HOME}/y";
+        lei_ok qw(add-external), "$ro_home/t1";
+        lei_ok qw(q mid:testmessage@example.com -o), $x;
+        lei_ok qw(q mid:testmessage@example.com -o), $y;
+        my @x = glob("$x/cur/*");
+        my @y = glob("$y/cur/*");
+        scalar(@x) == 1 or xbail 'expected 1 file', \@x;
+        scalar(@y) == 1 or xbail 'expected 1 file', \@y;
+
+        my $oid = '9bf1002c49eb075df47247b74d69bcd555e23422';
+        lei_ok qw(inspect), "blob:$oid";
+        my $ins = json_utf8->decode($lei_out);
+        my $exp = { "maildir:$x" => [ map { basename($_) } @x ],
+                "maildir:$y" => [ map { basename($_) } @y ] };
+        is_deeply($ins->{'mail-sync'}, $exp, 'inspect as expected');
+        lei_ok qw(add-watch), $x;
+        my $dst = $x[0] . 'S';
+        rename($x[0], $dst) or xbail "rename($x[0], $dst): $!";
+        tick($tick); # wait for inotify or kevent
+        my @y2 = glob("$y/*/*");
+        is_deeply(\@y2, [ "$y[0]S" ], "`seen' kw propagated to `y' dir");
+        lei_ok qw(note-event done);
+        lei_ok qw(inspect), "blob:$oid";
+        $ins = json_utf8->decode($lei_out);
+        $exp = { "maildir:$x" => [ map { basename($_) } glob("$x/*/*") ],
+                "maildir:$y" => [ map { basename($_) } glob("$y/*/*") ] };
+        is_deeply($ins->{'mail-sync'}, $exp, 'mail_sync matches FS');
+});
+
+done_testing;