From a14bc9e6cdd70f38eaa2961d1ea775300b9577ea Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 19 Jan 2021 09:34:31 +0000 Subject: lei q: fix augment of compressed mailboxes We need to delay writing out the mailbox until the compressor process is up and running, so have startq wait a bit. This means we must create the pipe early and hand it off to the workers before augmenting, despite spawning the gzip/pigz/xz/bzip2 process after augment is complete. --- t/lei.t | 42 ++++++++++++++++++++++++++---------------- t/lei_to_mail.t | 4 ++-- 2 files changed, 28 insertions(+), 18 deletions(-) (limited to 't') diff --git a/t/lei.t b/t/lei.t index c4692217..8eede13e 100644 --- a/t/lei.t +++ b/t/lei.t @@ -189,25 +189,35 @@ my $test_external = sub { # No double-quoting should be imposed on users on the CLI $lei->('q', 's:use boolean prefix'); like($out, qr/search: use boolean prefix/, 'phrase search got result'); + require IO::Uncompress::Gunzip; + for my $sfx ('', '.gz') { + my $f = "$home/mbox$sfx"; + $lei->('q', '-o', "mboxcl2:$f", 's:use boolean prefix'); + my $cat = $sfx eq '' ? sub { + open my $mb, '<', $f or fail "no mbox: $!"; + <$mb> + } : sub { + my $z = IO::Uncompress::Gunzip->new($f, MultiStream=>1); + <$z>; + }; + my @s = grep(/^Subject:/, $cat->()); + is(scalar(@s), 1, "1 result in mbox$sfx"); + $lei->('q', '-a', '-o', "mboxcl2:$f", 's:see attachment'); + is($err, '', 'no errors from augment'); + @s = grep(/^Subject:/, my @wtf = $cat->()); + is(scalar(@s), 2, "2 results in mbox$sfx"); - $lei->('q', '-o', "mboxcl2:$home/mbox", 's:use boolean prefix'); - open my $mb, '<', "$home/mbox" or fail "no mbox: $!"; - my @s = grep(/^Subject:/, <$mb>); - is(scalar(@s), 1, '1 result in mbox'); - $lei->('q', '-a', '-o', "mboxcl2:$home/mbox", 's:see attachment'); - is($err, '', 'no errors from augment'); - seek($mb, 0, SEEK_SET) or BAIL_OUT "seek: $!"; - @s = grep(/^Subject:/, <$mb>); - is(scalar(@s), 2, '2 results in mbox'); + $lei->('q', '-a', '-o', "mboxcl2:$f", 's:nonexistent'); + is($err, '', "no errors on no results ($sfx)"); - $lei->('q', '-a', '-o', "mboxcl2:$home/mbox", 's:nonexistent'); - is($err, '', 'no errors on no results'); - seek($mb, 0, SEEK_SET) or BAIL_OUT "seek: $!"; - my @s2 = grep(/^Subject:/, <$mb>); - is_deeply(\@s2, \@s, 'same 2 old results w/ --augment and bad search'); + my @s2 = grep(/^Subject:/, $cat->()); + is_deeply(\@s2, \@s, + "same 2 old results w/ --augment and bad search $sfx"); - $lei->('q', '-o', "mboxcl2:$home/mbox", 's:nonexistent'); - is(-s "$home/mbox", 0, 'clobber w/o --augment'); + $lei->('q', '-o', "mboxcl2:$f", 's:nonexistent'); + my @res = $cat->(); + is_deeply(\@res, [], "clobber w/o --augment $sfx"); + } }; my $test_lei_common = sub { diff --git a/t/lei_to_mail.t b/t/lei_to_mail.t index e5ac8eac..6673d9a6 100644 --- a/t/lei_to_mail.t +++ b/t/lei_to_mail.t @@ -94,9 +94,9 @@ my $wcb_get = sub { my $dup = Storable::thaw(Storable::freeze($l2m)); is_deeply($dup, $l2m, "$fmt round-trips through storable"); } - $l2m->pre_augment($lei); + my $zpipe = $l2m->pre_augment($lei); $l2m->do_augment($lei); - $l2m->post_augment($lei); + $l2m->post_augment($lei, $zpipe); my $cb = $l2m->write_cb($lei); delete $lei->{1}; $cb; -- cgit v1.2.3-24-ge0c7