2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # ensure we detect errors in lei/store
6 use PublicInbox::TestCommon;
7 use autodie qw(pipe open close seek);
8 use Fcntl qw(SEEK_SET);
9 use File::Path qw(remove_tree);
11 my $start_home = $ENV{HOME}; # bug guard
12 my $utf8_oid = '9bf1002c49eb075df47247b74d69bcd555e23422';
14 lei_ok qw(import -q t/plack-qp.eml); # start the store
15 ok(!lei(qw(blob --mail), $utf8_oid), 't/utf8.eml not imported, yet');
18 pipe($opt->{0}, my $in_w);
19 open $opt->{1}, '+>', undef;
20 open $opt->{2}, '+>', undef;
21 $opt->{-CLOFORK} = [ $in_w ];
22 my $cmd = [ qw(lei import -q -F mboxrd) ];
23 my $tp = start_script($cmd, undef, $opt);
26 print $in_w <<EOM or xbail "print: $!";
27 From k\@y Fri Oct 2 00:00:00 1993
28 From: <k\@example.com>
29 Date: Sat, 02 Oct 2010 00:00:00 +0000
35 # import another message w/ delay while mboxrd import is still running
36 lei_ok qw(import -q --commit-delay=300 t/utf8.eml);
37 lei_ok qw(blob --mail), $utf8_oid,
38 \'blob immediately available despite --commit-delay';
39 lei_ok qw(q m:testmessage@example.com);
40 is($lei_out, "[null]\n", 'delayed commit is unindexed');
42 # make immediate ->sto_barrier_request fail from mboxrd import:
43 remove_tree("$ENV{HOME}/.local/share/lei/store");
44 # subsequent lei commands are undefined behavior,
45 # but we need to make sure the current lei command fails:
47 close $in_w; # should trigger ->done
49 isnt($?, 0, 'lei import -F mboxrd error code set on failure');
50 is(-s $opt->{1}, 0, 'nothing in stdout');
51 isnt(-s $opt->{2}, 0, 'stderr not empty');
52 seek($opt->{2}, 0, SEEK_SET);
53 my @err = readline($opt->{2});
54 ok(grep(!/^#/, @err), 'noted error in stderr') or diag "@err";