lei/store: stop shard workers + cat-file on idle
[public-inbox.git] / t / tail_notify.t
blob82480ebc7e4413fe256995d6019a97d933127179
1 #!perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use v5.12;
5 use PublicInbox::TestCommon;
6 use POSIX qw(_exit);
7 my ($tmpdir, $for_destroy) = tmpdir();
8 use_ok 'PublicInbox::TailNotify';
9 my $f = "$tmpdir/log";
10 open my $fh, '>>', $f or xbail $!;
11 my $tn = PublicInbox::TailNotify->new($f);
12 my @x = $tn->getlines(1);
13 is_deeply(\@x, [], 'nothing, yet');
14 my $pid = fork // xbail "fork: $!";
15 if ($pid == 0) {
16         tick;
17         syswrite $fh, "hi\n" // xbail "syswrite: $!";
18         _exit(0);
20 @x = $tn->getlines;
21 is_deeply(\@x, [ "hi\n" ], 'got line');
22 waitpid($pid, 0) // xbail "waitpid: $!";
23 is($?, 0, 'writer done');
25 $pid = fork // xbail "fork: $!";
26 if ($pid == 0) {
27         tick;
28         unlink $f // xbail "unlink($f): $!";
29         open $fh, '>>', $f or xbail $!;
30         syswrite $fh, "bye\n" // xbail "syswrite: $!";
31         _exit(0);
33 @x = $tn->getlines;
34 is_deeply(\@x, [ "bye\n" ], 'got line after reopen');
35 waitpid($pid, 0) // xbail "waitpid: $!";
36 is($?, 0, 'writer done');
38 done_testing;