lei/store: stop shard workers + cat-file on idle
[public-inbox.git] / t / fake_inotify.t
blob8221e092a218c8c1e91e447faa06fd5d50296367
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>
5 # Ensure FakeInotify can pick up rename(2) and link(2) operations
6 # used by Maildir writing tools
7 use v5.12;
8 use PublicInbox::TestCommon;
9 use_ok 'PublicInbox::FakeInotify';
10 my ($tmpdir, $for_destroy) = tmpdir();
11 mkdir "$tmpdir/new" or BAIL_OUT "mkdir: $!";
12 mkdir "$tmpdir/new/rmd" or BAIL_OUT "mkdir: $!";
13 open my $fh, '>', "$tmpdir/tst" or BAIL_OUT "open: $!";
14 close $fh or BAIL_OUT "close: $!";
16 my $fi = PublicInbox::FakeInotify->new;
17 my $mask = PublicInbox::FakeInotify::MOVED_TO_OR_CREATE();
18 my $w = $fi->watch("$tmpdir/new", $mask);
20 rename("$tmpdir/tst", "$tmpdir/new/tst") or BAIL_OUT "rename: $!";
21 my @events = map { $_->fullname } $fi->read;
22 is_deeply(\@events, ["$tmpdir/new/tst"], 'rename(2) detected') or
23         diag explain(\@events);
25 open $fh, '>', "$tmpdir/tst" or BAIL_OUT "open: $!";
26 close $fh or BAIL_OUT "close: $!";
27 link("$tmpdir/tst", "$tmpdir/new/link") or BAIL_OUT "link: $!";
28 @events = map { $_->fullname } $fi->read;
29 is_deeply(\@events, ["$tmpdir/new/link"], 'link(2) detected') or
30         diag explain(\@events);
32 $w->cancel;
33 link("$tmpdir/new/tst", "$tmpdir/new/link2") or BAIL_OUT "link: $!";
34 @events = map { $_->fullname } $fi->read;
35 is_deeply(\@events, [], 'link(2) not detected after cancel') or
36         diag explain(\@events);
37 $fi->watch("$tmpdir/new", PublicInbox::FakeInotify::IN_DELETE());
39 rmdir("$tmpdir/new/rmd") or xbail "rmdir: $!";
40 @events = $fi->read;
41 is_deeply([map{ $_->fullname }@events], ["$tmpdir/new/rmd"], 'rmdir detected') or
42         diag explain(\@events);
43 ok($events[-1]->IN_DELETE, 'IN_DELETE set on rmdir');
45 unlink("$tmpdir/new/tst") or xbail "unlink: $!";
46 @events = grep { ref =~ /Gone/ } $fi->read;
47 is_deeply([map{ $_->fullname }@events], ["$tmpdir/new/tst"], 'unlink detected') or
48         diag explain(\@events);
49 ok($events[0]->IN_DELETE, 'IN_DELETE set on unlink');
51 done_testing;