From 1bc3707e3e0983c9aed898980ec8acf6501813f7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Jul 2020 03:32:56 +0000 Subject: inboxidle: avoid per-inbox anonymous subs Anonymous subs cost over 5K each on x86-64. So prefer the less-recommended-but-still-documented way of using Linux::Inotify2::watch to register watchers. This also updates FakeInotify to detect modifications correctly when used on systems with neither IO::KQueue nor Linux::Inotify2. --- t/fake_inotify.t | 18 +++++++----------- t/kqnotify.t | 12 ++++-------- 2 files changed, 11 insertions(+), 19 deletions(-) (limited to 't') diff --git a/t/fake_inotify.t b/t/fake_inotify.t index f0db0cb5..11dac117 100644 --- a/t/fake_inotify.t +++ b/t/fake_inotify.t @@ -16,29 +16,25 @@ close $fh or BAIL_OUT "close: $!"; my $fi = PublicInbox::FakeInotify->new; my $mask = PublicInbox::FakeInotify::MOVED_TO_OR_CREATE(); -my $hit = []; -my $cb = sub { push @$hit, map { $_->fullname } @_ }; -my $w = $fi->watch("$tmpdir/new", $mask, $cb); +my $w = $fi->watch("$tmpdir/new", $mask); select undef, undef, undef, $MIN_FS_TICK; rename("$tmpdir/tst", "$tmpdir/new/tst") or BAIL_OUT "rename: $!"; -$fi->poll; -is_deeply($hit, ["$tmpdir/new/tst"], 'rename(2) detected'); +my @events = map { $_->fullname } $fi->read; +is_deeply(\@events, ["$tmpdir/new/tst"], 'rename(2) detected'); -@$hit = (); select undef, undef, undef, $MIN_FS_TICK; open $fh, '>', "$tmpdir/tst" or BAIL_OUT "open: $!"; close $fh or BAIL_OUT "close: $!"; link("$tmpdir/tst", "$tmpdir/new/link") or BAIL_OUT "link: $!"; -$fi->poll; -is_deeply($hit, ["$tmpdir/new/link"], 'link(2) detected'); +@events = map { $_->fullname } $fi->read; +is_deeply(\@events, ["$tmpdir/new/link"], 'link(2) detected'); $w->cancel; -@$hit = (); select undef, undef, undef, $MIN_FS_TICK; link("$tmpdir/new/tst", "$tmpdir/new/link2") or BAIL_OUT "link: $!"; -$fi->poll; -is_deeply($hit, [], 'link(2) not detected after cancel'); +@events = map { $_->fullname } $fi->read; +is_deeply(\@events, [], 'link(2) not detected after cancel'); PublicInbox::DS->Reset; diff --git a/t/kqnotify.t b/t/kqnotify.t index b3414b8a..c3557d3e 100644 --- a/t/kqnotify.t +++ b/t/kqnotify.t @@ -17,25 +17,21 @@ close $fh or BAIL_OUT "close: $!"; my $kqn = PublicInbox::KQNotify->new; my $mask = PublicInbox::KQNotify::MOVED_TO_OR_CREATE(); -my $hit = []; -my $cb = sub { push @$hit, map { $_->fullname } @_ }; -my $w = $kqn->watch("$tmpdir/new", $mask, $cb); +my $w = $kqn->watch("$tmpdir/new", $mask); rename("$tmpdir/tst", "$tmpdir/new/tst") or BAIL_OUT "rename: $!"; -$kqn->poll; +my $hit = [ map { $_->fullname } $kqn->read ]; is_deeply($hit, ["$tmpdir/new/tst"], 'rename(2) detected (via NOTE_EXTEND)'); -@$hit = (); open $fh, '>', "$tmpdir/tst" or BAIL_OUT "open: $!"; close $fh or BAIL_OUT "close: $!"; link("$tmpdir/tst", "$tmpdir/new/link") or BAIL_OUT "link: $!"; -$kqn->poll; +$hit = [ grep m!/link$!, map { $_->fullname } $kqn->read ]; is_deeply($hit, ["$tmpdir/new/link"], 'link(2) detected (via NOTE_WRITE)'); $w->cancel; -@$hit = (); link("$tmpdir/new/tst", "$tmpdir/new/link2") or BAIL_OUT "link: $!"; -$kqn->poll; +$hit = [ map { $_->fullname } $kqn->read ]; is_deeply($hit, [], 'link(2) not detected after cancel'); done_testing; -- cgit v1.2.3-24-ge0c7