]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/TestCommon.pm
test_common: clear XDG_CACHE_HOME before lei tests
[public-inbox.git] / lib / PublicInbox / TestCommon.pm
index 57f1db952e49f7000cc509809d46ef89e14b3ee5..052d6e45e45b498809ec2a79cbc0731c66d78918 100644 (file)
@@ -429,7 +429,8 @@ sub tail_f (@) {
        require PublicInbox::Spawn;
        my $pid = PublicInbox::Spawn::spawn($cmd, undef, { 1 => 2 });
        wait_for_tail($pid, scalar @_);
-       PublicInboxTestProcess->new($pid, \&wait_for_tail);
+       require PublicInbox::AutoReap;
+       PublicInbox::AutoReap->new($pid, \&wait_for_tail);
 }
 
 sub start_script {
@@ -492,7 +493,8 @@ sub start_script {
                        die "FAIL: ",join(' ', $key, @argv), ": $!\n";
                }
        }
-       my $td = PublicInboxTestProcess->new($pid);
+       require PublicInbox::AutoReap;
+       my $td = PublicInbox::AutoReap->new($pid);
        $td->{-extra} = $tail;
        $td;
 }
@@ -554,16 +556,20 @@ SKIP: {
        require_git(2.6, 1) or skip('git 2.6+ required for lei test', 2);
        my $mods = $test_opt->{mods} // [ 'lei' ];
        require_mods(@$mods, 2);
+
+       # set PERL_INLINE_DIRECTORY before clobbering XDG_CACHE_HOME
+       require PublicInbox::Spawn;
        require PublicInbox::Config;
        require File::Path;
+
        local %ENV = %ENV;
        delete $ENV{XDG_DATA_HOME};
        delete $ENV{XDG_CONFIG_HOME};
+       delete $ENV{XDG_CACHE_HOME};
        $ENV{GIT_COMMITTER_EMAIL} = 'lei@example.com';
        $ENV{GIT_COMMITTER_NAME} = 'lei user';
        my (undef, $fn, $lineno) = caller(0);
        my $t = "$fn:$lineno";
-       require PublicInbox::Spawn;
        state $lei_daemon = PublicInbox::Spawn->can('send_cmd4') ||
                                eval { require Socket::MsgHdr; 1 };
        unless ($lei_daemon) {
@@ -672,8 +678,10 @@ sub create_inbox ($$;@) {
        my %opt = @_;
        require PublicInbox::Lock;
        require PublicInbox::InboxWritable;
+       require PublicInbox::Import;
        my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
-       my $dir = "t/data-gen/$base.$ident";
+       my ($db) = (PublicInbox::Import::default_branch() =~ m!([^/]+)\z!);
+       my $dir = "t/data-gen/$base.$ident-$db";
        my $new = !-d $dir;
        if ($new) {
                mkdir $dir; # may race
@@ -742,37 +750,6 @@ sub test_httpd ($$;$) {
 };
 
 
-package PublicInboxTestProcess;
-use strict;
-
-# prevent new threads from inheriting these objects
-sub CLONE_SKIP { 1 }
-
-sub new {
-       my ($cls, $pid, $cb) = @_;
-       bless { pid => $pid, cb => $cb, owner => $$ }, $cls;
-}
-
-sub kill {
-       my ($self, $sig) = @_;
-       CORE::kill($sig // 'TERM', $self->{pid});
-}
-
-sub join {
-       my ($self, $sig) = @_;
-       my $pid = delete $self->{pid} or return;
-       $self->{cb}->() if defined $self->{cb};
-       CORE::kill($sig, $pid) if defined $sig;
-       my $ret = waitpid($pid, 0) // die "waitpid($pid): $!";
-       $ret == $pid or die "waitpid($pid) != $ret";
-}
-
-sub DESTROY {
-       my ($self) = @_;
-       return if $self->{owner} != $$;
-       $self->join('TERM');
-}
-
 package PublicInbox::TestCommon::InboxWakeup;
 use strict;
 sub on_inbox_unlock { ${$_[0]}->($_[1]) }