From 64b1ce9f94127fc144d6205bb572fe43b4b552c2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 25 Mar 2021 06:20:23 +0200 Subject: tests: "check-run" uses persistent lei daemon 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. --- lib/PublicInbox/TestCommon.pm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'lib') 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}) { -- cgit v1.2.3-24-ge0c7