user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 08/10] lei import: force store, improve test diagnostics
  2021-03-25  4:20  7% [PATCH 00/10] lei testing improvements Eric Wong
@ 2021-03-25  4:20  5% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-03-25  4:20 UTC (permalink / raw)
  To: meta

"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');

^ permalink raw reply related	[relevance 5%]

* [PATCH 00/10] lei testing improvements
@ 2021-03-25  4:20  7% Eric Wong
  2021-03-25  4:20  5% ` [PATCH 08/10] lei import: force store, improve test diagnostics Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-03-25  4:20 UTC (permalink / raw)
  To: meta

[7/10] is the centerpiece and gives a ~10% speedup for tests,
which are still slow to me.  Speedup or not, it's uncovered a
bunch of subtle bugs over the past few days so I'm glad I
worked on it.

There's still some rare errors that come from looping
"make check-run TEST_LEI_ERR_LOUD" which I'm still trying
to figure out...

Eric Wong (10):
  test_common: cleanup inbox objects after use
  lei: janky $PATH2CFG garbage collection
  test_common: TEST_LEI_ERR_LOUD does not hide path names
  lei add-external: do not initialize writable store
  lei_mirror: don't show success on failure
  t/*: drop unnecessary v1-specific index calls
  tests: "check-run" uses persistent lei daemon
  lei import: force store, improve test diagnostics
  t/cmd_ipc: workaround signal handling raciness
  t/lei: add more diagnostics for failures

 lib/PublicInbox/LEI.pm         |  6 +++++
 lib/PublicInbox/LeiExternal.pm |  2 --
 lib/PublicInbox/LeiImport.pm   |  6 ++---
 lib/PublicInbox/LeiMirror.pm   | 11 ++++++---
 lib/PublicInbox/TestCommon.pm  | 41 +++++++++++++++++++++++-----------
 t/cmd_ipc.t                    | 28 ++++++++++++++++-------
 t/inbox_idle.t                 |  2 --
 t/lei-externals.t              |  7 ++++--
 t/lei-import-maildir.t         | 13 +++++++----
 t/lei-mark.t                   |  2 +-
 t/lei-mirror.t                 | 18 +++++++++++++++
 t/lei-q-kw.t                   |  6 ++---
 t/lei-q-thread.t               | 15 +++++++------
 t/nntpd.t                      |  4 ----
 t/run.perl                     | 19 ++++++++++++++++
 t/v2mda.t                      |  4 ----
 t/watch_filter_rubylang.t      |  7 ++----
 17 files changed, 130 insertions(+), 61 deletions(-)

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-03-25  4:20  7% [PATCH 00/10] lei testing improvements Eric Wong
2021-03-25  4:20  5% ` [PATCH 08/10] lei import: force store, improve test diagnostics Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).