]> Sergey Matveev's repositories - public-inbox.git/commitdiff
tests|lei: fixes for TEST_RUN_MODE=0 and lei oneshot
authorEric Wong <e@80x24.org>
Tue, 9 Feb 2021 08:09:37 +0000 (07:09 -0100)
committerEric Wong <e@80x24.org>
Wed, 10 Feb 2021 06:59:10 +0000 (06:59 +0000)
DESTROY callbacks can clobber $?, so we must take care to
preserve it when exiting.  We'll also try to make an effort to
ensure better DESTROY ordering and delete as much as possible
before x_it finishes.

We also need to load PublicInbox::Config when setting up
public inboxes.

lib/PublicInbox/IPC.pm
lib/PublicInbox/LEI.pm
lib/PublicInbox/TestCommon.pm
t/lei-mirror.t

index 9331233a87931fa6351a673b5c432f2a708bc5da..efac4c4dd9a145372a96d2de0e37d6b7ff2e1252 100644 (file)
@@ -412,9 +412,11 @@ sub DESTROY {
        my ($self) = @_;
        my $ppid = $self->{-wq_ppid};
        wq_kill($self) if $ppid && $ppid == $$;
+       my $err = $?;
        wq_close($self);
        wq_wait_old($self);
        ipc_worker_stop($self);
+       $? = $err if $err;
 }
 
 sub detect_nproc () {
index 5f2650876b2844dd9da18b168c77e9e7125631a9..dd831c54b1879bcfd3c67223332d50534820cf30 100644 (file)
@@ -336,8 +336,9 @@ sub x_it ($$) {
                        my $wq = delete $self->{$f} or next;
                        $wq->DESTROY;
                }
-               # cleanup anything that has tempfiles
-               delete @$self{qw(ovv dedupe)};
+               # cleanup anything that has tempfiles or open file handles
+               %PATH2CFG = ();
+               delete @$self{qw(ovv dedupe sto cfg)};
                if (my $signum = ($code & 127)) { # usually SIGPIPE (13)
                        $SIG{PIPE} = 'DEFAULT'; # $SIG{$signum} doesn't work
                        kill $signum, $$;
@@ -1072,8 +1073,10 @@ sub DESTROY {
        my ($self) = @_;
        $self->{1}->autoflush(1) if $self->{1};
        stop_pager($self);
+       my $err = $?;
        my $oneshot_pids = delete $self->{"pid.$self.$$"} or return;
        waitpid($_, 0) for keys %$oneshot_pids;
+       $? = $err if $err; # preserve ->fail or ->x_it code
 }
 
 1;
index 53f134371e046342b14c35644eb1975f6c8333b0..63d45ac396bd31c8da6d694748e5092fe317cd3f 100644 (file)
@@ -541,7 +541,6 @@ sub setup_public_inboxes () {
        my $end = $lk->lock_for_scope;
        return @ret if -f $stamp;
 
-       require PublicInbox::InboxWritable;
        local $ENV{PI_CONFIG} = $pi_config;
        for my $V (1, 2) {
                run_script([qw(-init), "-V$V", "t$V",
@@ -549,6 +548,8 @@ sub setup_public_inboxes () {
                                "$test_home/t$V", "http://example.com/t$V",
                                "t$V\@example.com" ]) or BAIL_OUT "init v$V";
        }
+       require PublicInbox::Config;
+       require PublicInbox::InboxWritable;
        my $cfg = PublicInbox::Config->new;
        my $seen = 0;
        $cfg->each_inbox(sub {
index e3707979d8d16d19fb41f32f7836c38f9e0b603f..cbe300dac047fb9f412eb29f79752a66d92515c2 100644 (file)
@@ -27,7 +27,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
        like($lei_out, qr!\Q$t2\E!, 't2 added to ls-externals');
 
        ok(!$lei->('add-external', $t2, '--mirror', "$http/t2/"),
-               '--mirror fails if reused');
+               '--mirror fails if reused') or diag "$lei_err.$lei_out = $?";
 
        ok($lei->('ls-external'), 'ls-external');
        like($lei_out, qr!\Q$t2\E!, 'still in ls-externals');