about summary refs log tree commit homepage
path: root/lib/PublicInbox/TestCommon.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-25 06:20:23 +0200
committerEric Wong <e@80x24.org>2021-03-25 17:59:02 +0000
commit64b1ce9f94127fc144d6205bb572fe43b4b552c2 (patch)
treee26985939415d1e2e94abfbaec98d6be44a95a44 /lib/PublicInbox/TestCommon.pm
parent08b14e417843557ec6a42fd9e5f0cedbd81832e8 (diff)
downloadpublic-inbox-64b1ce9f94127fc144d6205bb572fe43b4b552c2.tar.gz
We'll use a lei-daemon if it's already running and
TEST_LEI_DAEMON_PERSIST_DIR is set, but we can also start
one and manage it from t/run.perl

This drops "make check-run TEST_LEI_DAEMON_ONLY=1"
time by ~10% for me.
Diffstat (limited to 'lib/PublicInbox/TestCommon.pm')
-rw-r--r--lib/PublicInbox/TestCommon.pm22
1 files changed, 15 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}) {