about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/PublicInbox/TestCommon.pm22
-rw-r--r--t/lei-externals.t4
-rwxr-xr-xt/run.perl19
3 files changed, 38 insertions, 7 deletions
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index ffff5902..ca165a04 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -515,22 +515,30 @@ EOM
         my ($daemon_pid, $for_destroy, $daemon_xrd);
         my $tmpdir = $test_opt->{tmpdir};
         ($tmpdir, $for_destroy) = tmpdir unless $tmpdir;
+        state $persist_xrd = $ENV{TEST_LEI_DAEMON_PERSIST_DIR};
         SKIP: {
                 skip 'TEST_LEI_ONESHOT set', 1 if $ENV{TEST_LEI_ONESHOT};
                 my $home = "$tmpdir/lei-daemon";
                 mkdir($home, 0700) or BAIL_OUT "mkdir: $!";
                 local $ENV{HOME} = $home;
-                $daemon_xrd = "$home/xdg_run";
-                mkdir($daemon_xrd, 0700) or BAIL_OUT "mkdir: $!";
+                my $persist;
+                if ($persist_xrd && !$test_opt->{daemon_only}) {
+                        $persist = $daemon_xrd = $persist_xrd;
+                } else {
+                        $daemon_xrd = "$home/xdg_run";
+                        mkdir($daemon_xrd, 0700) or BAIL_OUT "mkdir: $!";
+                }
                 local $ENV{XDG_RUNTIME_DIR} = $daemon_xrd;
                 $cb->();
-                lei_ok(qw(daemon-pid), \"daemon-pid after $t");
-                chomp($daemon_pid = $lei_out);
-                if ($daemon_pid) {
+                unless ($persist) {
+                        lei_ok(qw(daemon-pid), \"daemon-pid after $t");
+                        chomp($daemon_pid = $lei_out);
+                        if (!$daemon_pid) {
+                                fail("daemon not running after $t");
+                                skip 'daemon died unexpectedly', 2;
+                        }
                         ok(kill(0, $daemon_pid), "daemon running after $t");
                         lei_ok(qw(daemon-kill), \"daemon-kill after $t");
-                } else {
-                        fail("daemon not running after $t");
                 }
         }; # SKIP for lei_daemon
         unless ($test_opt->{daemon_only}) {
diff --git a/t/lei-externals.t b/t/lei-externals.t
index afd90d19..488bf5ad 100644
--- a/t/lei-externals.t
+++ b/t/lei-externals.t
@@ -57,6 +57,8 @@ SKIP: {
                 chomp(my $pid_after = $lei_out);
                 is($pid_after, $pid_before, 'pid unchanged') or
                         skip 'daemon died', 1;
+                skip 'not killing persistent lei-daemon', 2 if
+                                $ENV{TEST_LEI_DAEMON_PERSIST_DIR};
                 lei_ok 'daemon-kill';
                 my $alive = 1;
                 for (1..100) {
@@ -262,6 +264,8 @@ test_lei(sub {
         }
 
         {
+                skip 'TEST_LEI_DAEMON_PERSIST_DIR in use', 1 if
+                                        $ENV{TEST_LEI_DAEMON_PERSIST_DIR};
                 opendir my $dh, '.' or BAIL_OUT "opendir(.) $!";
                 my $od = PublicInbox::OnDestroy->new($$, sub {
                         chdir $dh or BAIL_OUT "chdir: $!"
diff --git a/t/run.perl b/t/run.perl
index e8512e18..1fb1c5f0 100755
--- a/t/run.perl
+++ b/t/run.perl
@@ -14,6 +14,7 @@ use strict;
 use v5.10.1;
 use IO::Handle; # ->autoflush
 use PublicInbox::TestCommon;
+use PublicInbox::Spawn;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 use Errno qw(EINTR);
 use Fcntl qw(:seek);
@@ -40,6 +41,20 @@ $OLDERR->autoflush(1);
 
 key2sub($_) for @tests; # precache
 
+my ($for_destroy, $lei_env, $lei_daemon_pid, $owner_pid);
+if (!$ENV{TEST_LEI_DAEMON_PERSIST_DIR} &&
+                (PublicInbox::Spawn->can('recv_cmd4') ||
+                        eval { require Socket::MsgHdr })) {
+        $lei_env = {};
+        ($lei_env->{XDG_RUNTIME_DIR}, $for_destroy) = tmpdir;
+        $ENV{TEST_LEI_DAEMON_PERSIST_DIR} = $lei_env->{XDG_RUNTIME_DIR};
+        run_script([qw(lei daemon-pid)], $lei_env, { 1 => \$lei_daemon_pid });
+        chomp $lei_daemon_pid;
+        $lei_daemon_pid =~ /\A[0-9]+\z/ or die "no daemon pid: $lei_daemon_pid";
+        kill(0, $lei_daemon_pid) or die "kill $lei_daemon_pid: $!";
+        $owner_pid = $$;
+}
+
 if ($shuffle) {
         require List::Util;
 } elsif (open(my $prove_state, '<', '.prove') && eval { require YAML::XS }) {
@@ -209,3 +224,7 @@ for (my $i = $repeat; $i != 0; $i--) {
 }
 
 print $OLDOUT "1..".($repeat * scalar(@tests))."\n" if $repeat >= 0;
+if ($lei_env && $$ == $owner_pid) {
+        my $opt = {}; # 1 => $OLDOUT, 2 => $OLDERR };
+        run_script([qw(lei daemon-kill)], $lei_env, $opt);
+}