2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use PublicInbox::Config;
9 require_mods(qw(DBD::SQLite));
10 require PublicInbox::SearchIdx;
11 use_ok 'PublicInbox::InboxIdle';
12 my ($tmpdir, $for_destroy) = tmpdir();
15 my $inboxdir = "$tmpdir/$V";
16 my $ibx = create_inbox "idle$V", tmpdir => $inboxdir, version => $V,
17 indexlevel => 'basic', -no_gc => 1, sub {
18 my ($im, $ibx) = @_; # capture
23 my $sidx = PublicInbox::SearchIdx->new($ibx, 1);
25 $sidx->set_metadata_once;
26 $sidx->idx_release; # allow watching on lockfile
28 my $obj = InboxIdleTestObj->new;
29 my $pi_cfg = PublicInbox::Config->new(\<<EOF);
30 publicinbox.inbox-idle.inboxdir=$inboxdir
31 publicinbox.inbox-idle.indexlevel=basic
32 publicinbox.inbox-idle.address=$ibx->{-primary_address}
34 my $ident = 'whatever';
35 $pi_cfg->each_inbox(sub { shift->subscribe_unlock($ident, $obj) });
36 my $ii = PublicInbox::InboxIdle->new($pi_cfg);
37 ok($ii, 'InboxIdle created');
39 skip('inotify or kqueue missing', 1) unless $ii->{sock};
40 ok(fileno($ii->{sock}) >= 0, 'fileno() gave valid FD');
42 my $im = $ibx->importer(0);
43 ok($im->add(eml_load('t/utf8.eml')), "$V added");
46 is(scalar @{$obj->{called}}, 1, 'called on unlock');
47 $pi_cfg->each_inbox(sub { shift->unsubscribe_unlock($ident) });
48 ok($im->add(eml_load('t/data/0001.patch')), "$V added #2");
51 is(scalar @{$obj->{called}}, 1, 'not called when unsubbed');
57 package InboxIdleTestObj;
60 sub new { bless {}, shift }
63 my ($self, $ibx) = @_;
64 push @{$self->{called}}, $ibx;