]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
t/inbox_idle: delay for low-res FS w/o inotify||kqueue
authorEric Wong <e@80x24.org>
Mon, 11 Nov 2024 21:56:53 +0000 (21:56 +0000)
committerEric Wong <e@80x24.org>
Tue, 12 Nov 2024 20:13:11 +0000 (20:13 +0000)
On systems without inotify||kqueue, changes are unreliably
detected on filesystems with low-resolution timestamps.  The
FakeInotify emulation can't detect changes properly in all
cases.  While this remains a problem for real-world use cases,
systems w/o inotify or IO::KQueue are probably rare, so we'll
just change this test case to accomodate old FSes which lack
high resolution timestamps.

Keep in mind that mounting an old FS on a modern kernel doesn't
automatically give it high-resolution timestamps.  I discovered
this problem because I still use an ancient ext3 FS created
decades ago on a modern kernel :x

t/inbox_idle.t

index 0ccffab73a60de44fec190b486e65b849229c637..94f3845c416c4deb8030bd5f6f58602afcb33f88 100644 (file)
@@ -9,6 +9,11 @@ require PublicInbox::SearchIdx;
 use_ok 'PublicInbox::InboxIdle';
 my ($tmpdir, $for_destroy) = tmpdir();
 
+# for non-inotify|kqueue systems w/ low-res FS timestamps
+# This only makes the test work, but either high-res FS timestamps
+# or inotify or kqueue support needs to be added to your system.
+my $poll_delay = 1;
+
 for my $V (1, 2) {
        my $inboxdir = "$tmpdir/$V";
        my $ibx = create_inbox "idle$V", tmpdir => $inboxdir, version => $V,
@@ -35,16 +40,21 @@ EOF
        my $ii = PublicInbox::InboxIdle->new($pi_cfg);
        ok($ii, 'InboxIdle created');
        SKIP: {
-               skip('inotify or kqueue missing', 1) unless $ii->{sock};
+               $ii->{sock} or skip
+'inotify or kqueue missing, expect real-world breakage on low-res FSes', 1;
                ok(fileno($ii->{sock}) >= 0, 'fileno() gave valid FD');
+               $poll_delay = 0;
        }
        my $im = $ibx->importer(0);
        ok($im->add(eml_load('t/utf8.eml')), "$V added");
+       tick $poll_delay if $poll_delay;
        $im->done;
        $ii->event_step;
-       is(scalar @{$obj->{called}}, 1, 'called on unlock');
+       is(scalar @{$obj->{called}}, 1, 'called on unlock') or
+               diag explain($obj);
        $pi_cfg->each_inbox(sub { shift->unsubscribe_unlock($ident) });
        ok($im->add(eml_load('t/data/0001.patch')), "$V added #2");
+       tick $poll_delay if $poll_delay;
        $im->done;
        $ii->event_step;
        is(scalar @{$obj->{called}}, 1, 'not called when unsubbed');