From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 989A31FC0B for ; Thu, 25 Mar 2021 04:20:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 07/10] tests: "check-run" uses persistent lei daemon Date: Thu, 25 Mar 2021 06:20:23 +0200 Message-Id: <20210325042026.11270-8-e@80x24.org> In-Reply-To: <20210325042026.11270-1-e@80x24.org> References: <20210325042026.11270-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 +++++++++++++++------- t/lei-externals.t | 4 ++++ t/run.perl | 19 +++++++++++++++++++ 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); +}