2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::TestCommon;
6 use PublicInbox::Config;
8 require_mods(qw(DBD::SQLite));
9 require PublicInbox::SearchIdx;
10 use_ok 'PublicInbox::InboxIdle';
11 use PublicInbox::InboxWritable;
12 my ($tmpdir, $for_destroy) = tmpdir();
15 my $inboxdir = "$tmpdir/$V";
16 mkdir $inboxdir or BAIL_OUT("mkdir: $!");
18 inboxdir => $inboxdir,
21 -primary_address => 'test@example.com',
22 indexlevel => 'basic',
24 my $ibx = PublicInbox::Inbox->new({ %opt });
25 $ibx = PublicInbox::InboxWritable->new($ibx);
26 my $obj = InboxIdleTestObj->new;
28 my $im = $ibx->importer(0);
30 my $sidx = PublicInbox::SearchIdx->new($ibx, 1);
32 $sidx->set_indexlevel;
33 $sidx->idx_release; # allow watching on lockfile
35 my $pi_config = PublicInbox::Config->new(\<<EOF);
36 publicinbox.inbox-idle.inboxdir=$inboxdir
37 publicinbox.inbox-idle.indexlevel=basic
38 publicinbox.inbox-idle.address=test\@example.com
40 my $ident = 'whatever';
41 $pi_config->each_inbox(sub { shift->subscribe_unlock($ident, $obj) });
42 my $ii = PublicInbox::InboxIdle->new($pi_config);
43 ok($ii, 'InboxIdle created');
45 skip('inotify or kqueue missing', 1) unless $ii->{sock};
46 ok(fileno($ii->{sock}) >= 0, 'fileno() gave valid FD');
48 ok($im->add(eml_load('t/utf8.eml')), "$V added");
50 PublicInbox::SearchIdx->new($ibx)->index_sync if $V == 1;
52 is(scalar @{$obj->{called}}, 1, 'called on unlock');
53 $pi_config->each_inbox(sub { shift->unsubscribe_unlock($ident) });
54 ok($im->add(eml_load('t/data/0001.patch')), "$V added #2");
56 PublicInbox::SearchIdx->new($ibx)->index_sync if $V == 1;
58 is(scalar @{$obj->{called}}, 1, 'not called when unsubbed');
64 package InboxIdleTestObj;
67 sub new { bless {}, shift }
70 my ($self, $ibx) = @_;
71 push @{$self->{called}}, $ibx;