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();
13 my $inboxdir = "$tmpdir/$V";
14 my $ibx = create_inbox "idle$V", tmpdir => $inboxdir, version => $V,
15 indexlevel => 'basic', -no_gc => 1, sub {
16 my ($im, $ibx) = @_; # capture
21 my $sidx = PublicInbox::SearchIdx->new($ibx, 1);
23 $sidx->set_metadata_once;
24 $sidx->idx_release; # allow watching on lockfile
26 my $obj = InboxIdleTestObj->new;
27 my $pi_cfg = cfg_new $tmpdir, <<EOF;
28 [publicinbox "inbox-idle"]
31 address = $ibx->{-primary_address}
33 my $ident = 'whatever';
34 $pi_cfg->each_inbox(sub { shift->subscribe_unlock($ident, $obj) });
35 my $ii = PublicInbox::InboxIdle->new($pi_cfg);
36 ok($ii, 'InboxIdle created');
38 skip('inotify or kqueue missing', 1) unless $ii->{sock};
39 ok(fileno($ii->{sock}) >= 0, 'fileno() gave valid FD');
41 my $im = $ibx->importer(0);
42 ok($im->add(eml_load('t/utf8.eml')), "$V added");
45 is(scalar @{$obj->{called}}, 1, 'called on unlock');
46 $pi_cfg->each_inbox(sub { shift->unsubscribe_unlock($ident) });
47 ok($im->add(eml_load('t/data/0001.patch')), "$V added #2");
50 is(scalar @{$obj->{called}}, 1, 'not called when unsubbed');
56 package InboxIdleTestObj;
59 sub new { bless {}, shift }
62 my ($self, $ibx) = @_;
63 push @{$self->{called}}, $ibx;