user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 07/10] tests: "check-run" uses persistent lei daemon
  2021-03-25  4:20  6% [PATCH 00/10] lei testing improvements Eric Wong
@ 2021-03-25  4:20  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-03-25  4:20 UTC (permalink / raw)
  To: meta

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);
+}

^ permalink raw reply related	[relevance 7%]

* [PATCH 00/10] lei testing improvements
@ 2021-03-25  4:20  6% Eric Wong
  2021-03-25  4:20  7% ` [PATCH 07/10] tests: "check-run" uses persistent lei daemon Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-03-25  4:20 UTC (permalink / raw)
  To: meta

[7/10] is the centerpiece and gives a ~10% speedup for tests,
which are still slow to me.  Speedup or not, it's uncovered a
bunch of subtle bugs over the past few days so I'm glad I
worked on it.

There's still some rare errors that come from looping
"make check-run TEST_LEI_ERR_LOUD" which I'm still trying
to figure out...

Eric Wong (10):
  test_common: cleanup inbox objects after use
  lei: janky $PATH2CFG garbage collection
  test_common: TEST_LEI_ERR_LOUD does not hide path names
  lei add-external: do not initialize writable store
  lei_mirror: don't show success on failure
  t/*: drop unnecessary v1-specific index calls
  tests: "check-run" uses persistent lei daemon
  lei import: force store, improve test diagnostics
  t/cmd_ipc: workaround signal handling raciness
  t/lei: add more diagnostics for failures

 lib/PublicInbox/LEI.pm         |  6 +++++
 lib/PublicInbox/LeiExternal.pm |  2 --
 lib/PublicInbox/LeiImport.pm   |  6 ++---
 lib/PublicInbox/LeiMirror.pm   | 11 ++++++---
 lib/PublicInbox/TestCommon.pm  | 41 +++++++++++++++++++++++-----------
 t/cmd_ipc.t                    | 28 ++++++++++++++++-------
 t/inbox_idle.t                 |  2 --
 t/lei-externals.t              |  7 ++++--
 t/lei-import-maildir.t         | 13 +++++++----
 t/lei-mark.t                   |  2 +-
 t/lei-mirror.t                 | 18 +++++++++++++++
 t/lei-q-kw.t                   |  6 ++---
 t/lei-q-thread.t               | 15 +++++++------
 t/nntpd.t                      |  4 ----
 t/run.perl                     | 19 ++++++++++++++++
 t/v2mda.t                      |  4 ----
 t/watch_filter_rubylang.t      |  7 ++----
 17 files changed, 130 insertions(+), 61 deletions(-)

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-03-25  4:20  6% [PATCH 00/10] lei testing improvements Eric Wong
2021-03-25  4:20  7% ` [PATCH 07/10] tests: "check-run" uses persistent lei daemon Eric Wong

Code repositories for project(s) associated with this public 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).