diff options
author | Eric Wong <e@80x24.org> | 2021-03-25 06:20:23 +0200 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-03-25 17:59:02 +0000 |
commit | 64b1ce9f94127fc144d6205bb572fe43b4b552c2 (patch) | |
tree | e26985939415d1e2e94abfbaec98d6be44a95a44 /t | |
parent | 08b14e417843557ec6a42fd9e5f0cedbd81832e8 (diff) | |
download | public-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 't')
-rw-r--r-- | t/lei-externals.t | 4 | ||||
-rwxr-xr-x | t/run.perl | 19 |
2 files changed, 23 insertions, 0 deletions
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: $!" @@ -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); +} |