unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/4] t/lei: fix TEST_RUN_MODE=0, simplify oneshot fallback
Date: Thu, 31 Dec 2020 17:47:48 -1200
Message-ID: <20210101054750.6771-3-e@80x24.org> (raw)
In-Reply-To: <20210101054750.6771-1-e@80x24.org>

We need to use an absolute path after chdir in run modes
where scripts aren't loaded into in-memory subs.

The oneshot test was also failing under TEST_RUN_MODE=0 due to
no "lei-oneshot" command existing on the FS.  So we force a
socket failure by making XDG_RUNTIME_DIR too large to fit into
the 108-byte .sun_path field of "struct sockaddr_un".  This
even lets us simplify lei-oneshot significantly.
---
 t/lei-oneshot.t | 17 -----------------
 t/lei.t         | 29 +++++++++++++++++------------
 2 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/t/lei-oneshot.t b/t/lei-oneshot.t
index 2b34f982..7688da5b 100644
--- a/t/lei-oneshot.t
+++ b/t/lei-oneshot.t
@@ -4,22 +4,5 @@
 use strict;
 use v5.10.1;
 use PublicInbox::TestCommon;
-$PublicInbox::TestCommon::cached_scripts{'lei-oneshot'} //= do {
-	eval <<'EOF';
-package LeiOneshot;
-use strict;
-use subs qw(exit);
-*exit = \&PublicInbox::TestCommon::run_script_exit;
-sub main {
-# the below "line" directive is a magic comment, see perlsyn(1) manpage
-# line 1 "lei-oneshot"
-	require PublicInbox::LEI;
-	PublicInbox::LEI::oneshot(__PACKAGE__);
-	0;
-}
-1;
-EOF
-	LeiOneshot->can('main');
-};
 local $ENV{TEST_LEI_ONESHOT} = '1';
 require './t/lei.t';
diff --git a/t/lei.t b/t/lei.t
index 690878ce..41638950 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -9,7 +9,6 @@ use PublicInbox::Config;
 use File::Path qw(rmtree);
 require_git 2.6;
 require_mods(qw(json DBD::SQLite Search::Xapian));
-my $LEI = 'lei';
 my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') };
 my $lei = sub {
 	my ($cmd, $env, $xopt) = @_;
@@ -18,13 +17,12 @@ my $lei = sub {
 		($env, $xopt) = grep { (!defined) || ref } @_;
 		$cmd = [ grep { defined && !ref } @_ ];
 	}
-	run_script([$LEI, @$cmd], $env, $xopt // $opt);
+	run_script(['lei', @$cmd], $env, $xopt // $opt);
 };
 
 my ($home, $for_destroy) = tmpdir();
 delete local $ENV{XDG_DATA_HOME};
 delete local $ENV{XDG_CONFIG_HOME};
-local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
 local $ENV{HOME} = $home;
 local $ENV{FOO} = 'BAR';
 mkdir "$home/xdg_run", 0700 or BAIL_OUT "mkdir: $!";
@@ -188,10 +186,16 @@ my $test_lei_common = sub {
 	$test_external->();
 };
 
-my $test_lei_oneshot = $ENV{TEST_LEI_ONESHOT};
-SKIP: {
-	last SKIP if $test_lei_oneshot;
+if ($ENV{TEST_LEI_ONESHOT}) {
+	require_ok 'PublicInbox::LEI';
+	# force sun_path[108] overflow, "IO::FDPass" avoids warning
+	local $ENV{XDG_RUNTIME_DIR} = "$home/IO::FDPass".('.sun_path' x 108);
+	$test_lei_common->();
+}
+
+SKIP: { # real socket
 	require_mods(qw(IO::FDPass Cwd), 46);
+	local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
 	my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/sock";
 
 	ok(run_script([qw(lei daemon-pid)], undef, $opt), 'daemon-pid');
@@ -275,11 +279,17 @@ SKIP: {
 	if ('oneshot on cwd gone') {
 		my $cwd = Cwd::fastcwd() or BAIL_OUT "fastcwd: $!";
 		my $d = "$home/to-be-removed";
+		my $lei_path = 'lei';
+		# we chdir, so we need an abs_path fur run_script
+		if (($ENV{TEST_RUN_MODE}//2) != 2) {
+			$lei_path = PublicInbox::TestCommon::key2script('lei');
+			$lei_path = Cwd::abs_path($lei_path);
+		}
 		mkdir $d or BAIL_OUT "mkdir($d) $!";
 		chdir $d or BAIL_OUT "chdir($d) $!";
 		if (rmdir($d)) {
 			$out = $err = '';
-			ok(run_script([qw(lei help)], undef, $opt),
+			ok(run_script([$lei_path, 'help'], undef, $opt),
 				'cwd fail, one-shot fallback works');
 		} else {
 			$err = "rmdir=$!";
@@ -296,11 +306,6 @@ SKIP: {
 	}
 	ok(!kill(0, $new_pid), 'daemon exits after unlink');
 	# success over socket, can't test without
-	$test_lei_common = undef;
 };
 
-require_ok 'PublicInbox::LEI';
-$LEI = 'lei-oneshot' if $test_lei_oneshot;
-$test_lei_common->() if $test_lei_common;
-
 done_testing;

  parent reply	other threads:[~2021-01-01  5:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-01  5:47 [PATCH 0/4] TEST_RUN_MODE=0 fixes Eric Wong
2021-01-01  5:47 ` [PATCH 1/4] search: do not use $QP_FLAGS until Xapian is loaded Eric Wong
2021-01-01  5:47 ` Eric Wong [this message]
2021-01-01  5:47 ` [PATCH 3/4] import: unset GIT_CONFIG with `git config --global' Eric Wong
2021-01-01  5:47 ` [PATCH 4/4] treewide: reduce load_xapian* callsites 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=20210101054750.6771-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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

unofficial mirror of meta@public-inbox.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://yhetil.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.mail.public-inbox.meta
	nntp://news.public-inbox.org/inbox.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git