From: Eric Wong <e@80x24.org> 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 [thread overview] Message-ID: <20210325042026.11270-8-e@80x24.org> (raw) In-Reply-To: <20210325042026.11270-1-e@80x24.org> 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); +}
next prev parent reply other threads:[~2021-03-25 4:20 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-25 4:20 [PATCH 00/10] lei testing improvements Eric Wong 2021-03-25 4:20 ` [PATCH 01/10] test_common: cleanup inbox objects after use Eric Wong 2021-03-25 4:20 ` [PATCH 02/10] lei: janky $PATH2CFG garbage collection Eric Wong 2021-03-25 4:20 ` [PATCH 03/10] test_common: TEST_LEI_ERR_LOUD does not hide path names Eric Wong 2021-03-25 4:20 ` [PATCH 04/10] lei add-external: do not initialize writable store Eric Wong 2021-03-25 4:20 ` [PATCH 05/10] lei_mirror: don't show success on failure Eric Wong 2021-03-25 4:20 ` [PATCH 06/10] t/*: drop unnecessary v1-specific index calls Eric Wong 2021-03-25 4:20 ` Eric Wong [this message] 2021-03-25 4:20 ` [PATCH 08/10] lei import: force store, improve test diagnostics Eric Wong 2021-03-25 4:20 ` [PATCH 09/10] t/cmd_ipc: workaround signal handling raciness Eric Wong 2021-03-25 4:20 ` [PATCH 10/10] t/lei: add more diagnostics for failures Eric Wong
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://public-inbox.org/README * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210325042026.11270-8-e@80x24.org \ --to=e@80x24.org \ --cc=meta@public-inbox.org \ --subject='Re: [PATCH 07/10] tests: "check-run" uses persistent lei daemon' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://80x24.org/public-inbox.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).