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 AFFA91FA12 for ; Fri, 1 Jan 2021 05:47:50 +0000 (UTC) From: Eric Wong 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> In-Reply-To: <20210101054750.6771-1-e@80x24.org> References: <20210101054750.6771-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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;