From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B5E571FC0C for ; Thu, 25 Mar 2021 04:20:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 08/10] lei import: force store, improve test diagnostics Date: Thu, 25 Mar 2021 06:20:24 +0200 Message-Id: <20210325042026.11270-9-e@80x24.org> In-Reply-To: <20210325042026.11270-1-e@80x24.org> References: <20210325042026.11270-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: "lei import" should never be without a {sto}, and *_done should not be called multiple times, so ensure we can fail if it's missing. Update some existing tests to complain loudly by introducing a handy "xbail" function which wraps "explain" and BAIL_OUT. BAIL_OUT was painful to type and concatenating the result of "explain" doesn't work as I thought it would since "explain" always returns an array, and BAIL_OUT only accepts a single scalar arg (unlike "die"). --- lib/PublicInbox/LeiImport.pm | 6 +++--- lib/PublicInbox/TestCommon.pm | 4 +++- t/lei-mark.t | 2 +- t/lei-q-kw.t | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index 9da6b7f9..7c5b7d09 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -39,14 +39,14 @@ sub import_done_wait { # dwaitpid callback my ($arg, $pid) = @_; my ($imp, $lei) = @$arg; $lei->child_error($?, 'non-fatal errors during import') if $?; - my $sto = delete $lei->{sto}; - my $wait = $sto->ipc_do('done') if $sto; # PublicInbox::LeiStore::done + my $sto = delete $lei->{sto} // return $lei->fail('BUG: {sto} gone'); + my $wait = $sto->ipc_do('done'); # PublicInbox::LeiStore::done $lei->dclose; } sub import_done { # EOF callback for main daemon my ($lei) = @_; - my $imp = delete $lei->{imp} or return; + my $imp = delete $lei->{imp} // return $lei->fail('BUG: {imp} gone'); $imp->wq_wait_old(\&import_done_wait, $lei); } diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index ca165a04..72617a78 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -17,7 +17,7 @@ BEGIN { run_script start_script key2sub xsys xsys_e xqx eml_load tick have_xapian_compact json_utf8 setup_public_inboxes create_inbox tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt - test_httpd); + test_httpd xbail); require Test::More; my @methods = grep(!/\W/, @Test::More::EXPORT); eval(join('', map { "*$_=\\&Test::More::$_;" } @methods)); @@ -25,6 +25,8 @@ BEGIN { push @EXPORT, @methods; } +sub xbail (@) { BAIL_OUT join(' ', map { ref ? (explain($_)) : ($_) } @_) } + sub eml_load ($) { my ($path, $cb) = @_; open(my $fh, '<', $path) or die "open $path: $!"; diff --git a/t/lei-mark.t b/t/lei-mark.t index ddf5634c..76995589 100644 --- a/t/lei-mark.t +++ b/t/lei-mark.t @@ -30,7 +30,7 @@ test_lei(sub { ok(-s $mb, 'wrote mbox result'); lei_ok(qw(q m:testmessage@example.com -o), $md); my @fn = glob("$md/cur/*"); - scalar(@fn) == 1 or BAIL_OUT 'no mail '.explain(\@fn); + scalar(@fn) == 1 or xbail $lei_err, 'no mail', \@fn; rename($fn[0], "$fn[0]S") or BAIL_OUT "rename $!"; $check_kw->(['flagged'], msg => 'after bad request'); lei_ok(qw(mark -F eml t/utf8.eml -kw:flagged)); diff --git a/t/lei-q-kw.t b/t/lei-q-kw.t index 4db27363..c17411fb 100644 --- a/t/lei-q-kw.t +++ b/t/lei-q-kw.t @@ -21,7 +21,7 @@ lei_ok(qw(import -F eml t/plack-qp.eml)); my $o = "$ENV{HOME}/dst"; lei_ok(qw(q -o), "maildir:$o", qw(m:qp@example.com)); my @fn = glob("$o/cur/*:2,"); -scalar(@fn) == 1 or BAIL_OUT "wrote multiple or zero files: ".explain(\@fn); +scalar(@fn) == 1 or xbail $lei_err, 'wrote multiple or zero files:', \@fn; rename($fn[0], "$fn[0]S") or BAIL_OUT "rename $!"; lei_ok(qw(q -o), "maildir:$o", qw(m:bogus-noresults@example.com)); @@ -124,7 +124,7 @@ lei_ok(qw(q -o), $o, "m:$m", @inc); # emulate MUA marking a Maildir message as read: @fn = glob("$o/cur/*"); -scalar(@fn) == 1 or BAIL_OUT "wrote multiple or zero files: ".explain(\@fn); +scalar(@fn) == 1 or xbail $lei_err, 'wrote multiple or zero files:', \@fn; rename($fn[0], "$fn[0]S") or BAIL_OUT "rename $!"; lei_ok(qw(q -o), $o, 'bogus', \'clobber output dir to import keywords'); @@ -178,7 +178,7 @@ $m = 'multipart@example.com'; $o = "$ENV{HOME}/fuzz"; lei_ok('q', '-o', $o, "m:$m", @inc); @fn = glob("$o/cur/*"); -scalar(@fn) == 1 or BAIL_OUT "wrote multiple or zero files: ".explain(\@fn); +scalar(@fn) == 1 or xbail $lei_err, "wrote multiple or zero files", \@fn; rename($fn[0], "$fn[0]S") or BAIL_OUT "rename $!"; lei_ok('q', '-o', $o, "m:$m"); is_deeply([glob("$o/cur/*")], [], 'clobbered output results');