X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fdir_idle.t;h=0bb3b7585328dc2308c315019b80320c53e4508c;hb=0c385e6500f26babc47a0768b730ea38e290a5f5;hp=d62eb5a26faa65be72bb0b47221fb7d23b4ced33;hpb=af0b0fb7a454470a32c452119d0392e0dedb3fe1;p=public-inbox.git
diff --git a/t/dir_idle.t b/t/dir_idle.t
index d62eb5a2..0bb3b758 100644
--- a/t/dir_idle.t
+++ b/t/dir_idle.t
@@ -1,6 +1,43 @@
#!perl -w
# Copyright (C) 2020-2021 all contributors
# License: AGPL-3.0+
-use Test::More;
+use v5.10.1; use strict; use PublicInbox::TestCommon;
+use PublicInbox::DS qw(now);
+use File::Path qw(make_path);
use_ok 'PublicInbox::DirIdle';
+my ($tmpdir, $for_destroy) = tmpdir();
+make_path("$tmpdir/a/b", "$tmpdir/c");
+my @x;
+my $cb = sub { push @x, \@_ };
+my $di = PublicInbox::DirIdle->new(["$tmpdir/a", "$tmpdir/c"], $cb, 1);
+PublicInbox::DS->SetLoopTimeout(1000);
+my $end = 3 + now;
+PublicInbox::DS->SetPostLoopCallback(sub { scalar(@x) == 0 && now < $end });
+tick(0.011);
+rmdir("$tmpdir/a/b") or xbail "rmdir $!";
+PublicInbox::DS->EventLoop;
+is(scalar(@x), 1, 'got an event') and
+ is($x[0]->[0]->fullname, "$tmpdir/a/b", 'got expected fullname') and
+ ok($x[0]->[0]->IN_DELETE, 'IN_DELETE set');
+
+tick(0.011);
+rmdir("$tmpdir/a") or xbail "rmdir $!";
+@x = ();
+$end = 3 + now;
+PublicInbox::DS->EventLoop;
+is(scalar(@x), 1, 'got an event') and
+ is($x[0]->[0]->fullname, "$tmpdir/a", 'got expected fullname') and
+ ok($x[0]->[0]->IN_DELETE_SELF, 'IN_DELETE_SELF set');
+
+tick(0.011);
+rename("$tmpdir/c", "$tmpdir/j") or xbail "rmdir $!";
+@x = ();
+$end = 3 + now;
+PublicInbox::DS->EventLoop;
+is(scalar(@x), 1, 'got an event') and
+ is($x[0]->[0]->fullname, "$tmpdir/c", 'got expected fullname') and
+ ok($x[0]->[0]->IN_DELETE_SELF || $x[0]->[0]->IN_MOVE_SELF,
+ 'IN_DELETE_SELF set on move');
+
+PublicInbox::DS->Reset;
done_testing;