]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/imapd.t
qspawn: learn to gzip streaming responses
[public-inbox.git] / t / imapd.t
index ee3a3b267671f549b30de54c53aba1f5a28f87d9..1ac6a4ab64ecc28c4dbdb00286e2d3ce29b2ef45 100644 (file)
--- a/t/imapd.t
+++ b/t/imapd.t
@@ -440,9 +440,11 @@ ok($mic->logout, 'logged out');
        like(<$c>, qr/\Atagonly BAD Error in IMAP command/, 'tag-only line');
 }
 
-{
+SKIP: {
        use_ok 'PublicInbox::WatchMaildir';
        use_ok 'PublicInbox::InboxIdle';
+       require_git('1.8.5', 1) or
+               skip('git 1.8.5+ needed for --urlmatch', 4);
        my $old_env = { HOME => $ENV{HOME} };
        my $home = "$tmpdir/watch_home";
        mkdir $home or BAIL_OUT $!;
@@ -466,7 +468,7 @@ ok($mic->logout, 'logged out');
        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 });
 
@@ -486,7 +488,7 @@ ok($mic->logout, 'logged out');
 
        # try again with polling
        xsys(qw(git config), "--file=$home/.public-inbox/config",
-               "imap.imap://$ihost:$iport.PollInterval", 0.11) == 0
+               'imap.PollInterval', 0.11) == 0
                or BAIL_OUT "git config $?";
        $w->kill('HUP');
        diag 'waiting for -watch reload + initial fetch';
@@ -510,11 +512,36 @@ ok($mic->logout, 'logged out');
        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');