From d75cbb9b69a780b6bbc37e243ada35dfd0c47552 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 4 Jul 2020 21:33:13 +0000 Subject: watch: don't burn CPU on IDLE failures Network connections fail and need to be detected sooner rather than later during IDLE to avoid backtrace floods. In case the IDLE process dies completely, don't respawn right away, either, to avoid entering a respawn loop. There's also a typo fix :P --- t/imapd.t | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/imapd.t b/t/imapd.t index cf327e9f..1ac6a4ab 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -468,7 +468,7 @@ SKIP: { my $obj = bless \$cb, 'PublicInbox::TestCommon::InboxWakeup'; $cfg->each_inbox(sub { $_[0]->subscribe_unlock('ident', $obj) }); my $watcherr = "$tmpdir/watcherr"; - open my $err_wr, '>', $watcherr or BAIL_OUT $!; + open my $err_wr, '>>', $watcherr or BAIL_OUT $!; open my $err, '<', $watcherr or BAIL_OUT $!; my $w = start_script(['-watch'], undef, { 2 => $err_wr }); @@ -512,11 +512,36 @@ SKIP: { seek($err, 0, 0); my @err = grep(!/^I:/, <$err>); is(@err, 0, 'no warnings/errors from -watch'.join(' ', @err)); + + if ($ENV{TEST_KILL_IMAPD}) { # not sure how reliable this test can be + xsys(qw(git config), "--file=$home/.public-inbox/config", + qw(--unset imap.PollInterval)) == 0 + or BAIL_OUT "git config $?"; + truncate($err_wr, 0) or BAIL_OUT $!; + my @t0 = times; + $w = start_script(['-watch'], undef, { 2 => $err_wr }); + seek($err, 0, 0); + tick until (grep(/I: \S+ idling/, <$err>)); + diag 'killing imapd, waiting for CPU spins'; + my $delay = 0.11; + $td->kill(9); + tick $delay; + $w->kill; + $w->join; + is($?, 0, 'no error in exited -watch process'); + my @t1 = times; + my $c = $t1[2] + $t1[3] - $t0[2] - $t0[3]; + my $thresh = (0.9 * $delay); + diag "c=$c, threshold=$thresh"; + ok($c < $thresh, 'did not burn much CPU'); + is_deeply([grep(/ line \d+$/m, <$err>)], [], + 'no backtraces from errors'); + } } $td->kill; $td->join; -is($?, 0, 'no error in exited process'); +is($?, 0, 'no error in exited process') if !$ENV{TEST_KILL_IMAPD}; open my $fh, '<', $err or BAIL_OUT("open $err failed: $!"); my $eout = do { local $/; <$fh> }; unlike($eout, qr/wide/i, 'no Wide character warnings'); -- cgit v1.2.3-24-ge0c7