2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::TestCommon;
7 require_mods(qw(DBD::SQLite));
8 require PublicInbox::SearchIdx;
9 use_ok 'PublicInbox::InboxIdle';
10 my ($tmpdir, $for_destroy) = tmpdir();
12 # for non-inotify|kqueue systems w/ low-res FS timestamps
13 # This only makes the test work, but either high-res FS timestamps
14 # or inotify or kqueue support needs to be added to your system.
18 my $inboxdir = "$tmpdir/$V";
19 my $ibx = create_inbox "idle$V", tmpdir => $inboxdir, version => $V,
20 indexlevel => 'basic', -no_gc => 1, sub {
21 my ($im, $ibx) = @_; # capture
26 my $sidx = PublicInbox::SearchIdx->new($ibx, 1);
28 $sidx->set_metadata_once;
29 $sidx->idx_release; # allow watching on lockfile
31 my $obj = InboxIdleTestObj->new;
32 my $pi_cfg = cfg_new $tmpdir, <<EOF;
33 [publicinbox "inbox-idle"]
36 address = $ibx->{-primary_address}
38 my $ident = 'whatever';
39 $pi_cfg->each_inbox(sub { shift->subscribe_unlock($ident, $obj) });
40 my $ii = PublicInbox::InboxIdle->new($pi_cfg);
41 ok($ii, 'InboxIdle created');
44 'inotify or kqueue missing, expect real-world breakage on low-res FSes', 1;
45 ok(fileno($ii->{sock}) >= 0, 'fileno() gave valid FD');
48 my $im = $ibx->importer(0);
49 ok($im->add(eml_load('t/utf8.eml')), "$V added");
50 tick $poll_delay if $poll_delay;
53 is(scalar @{$obj->{called}}, 1, 'called on unlock') or
55 $pi_cfg->each_inbox(sub { shift->unsubscribe_unlock($ident) });
56 ok($im->add(eml_load('t/data/0001.patch')), "$V added #2");
57 tick $poll_delay if $poll_delay;
60 is(scalar @{$obj->{called}}, 1, 'not called when unsubbed');
66 package InboxIdleTestObj;
69 sub new { bless {}, shift }
72 my ($self, $ibx) = @_;
73 push @{$self->{called}}, $ibx;