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 E3A381F4B4 for ; Mon, 14 Sep 2020 06:29:26 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] tests: consistently check for xapian-compact Date: Mon, 14 Sep 2020 06:29:26 +0000 Message-Id: <20200914062926.13313-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We may need to test against development versions of Xapian, which may rely on setting `XAPIAN_COMPACT=xapian-compact-1.5'. Ensure it's possible to do that. And add a missing check in t/xcpdb-reshard.t, too. --- lib/PublicInbox/TestCommon.pm | 9 ++++++++- t/convert-compact.t | 3 +-- t/indexlevels-mirror.t | 6 ++---- t/nntpd.t | 2 +- t/xcpdb-reshard.t | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 42819179..299b9c6a 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -10,7 +10,8 @@ use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek); use POSIX qw(dup2); use IO::Socket::INET; our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods - run_script start_script key2sub xsys xqx eml_load tick); + run_script start_script key2sub xsys xqx eml_load tick + have_xapian_compact); sub eml_load ($) { my ($path, $cb) = @_; @@ -397,6 +398,12 @@ sub start_script { PublicInboxTestProcess->new($pid, $tail_pid); } +sub have_xapian_compact () { + require PublicInbox::Spawn; + # $ENV{XAPIAN_COMPACT} is used by PublicInbox/Xapcmd.pm, too + PublicInbox::Spawn::which($ENV{XAPIAN_COMPACT} || 'xapian-compact'); +} + package PublicInboxTestProcess; use strict; diff --git a/t/convert-compact.t b/t/convert-compact.t index 575262e8..e479476d 100644 --- a/t/convert-compact.t +++ b/t/convert-compact.t @@ -4,11 +4,10 @@ use strict; use warnings; use Test::More; use PublicInbox::Eml; -use PublicInbox::Spawn qw(which); use PublicInbox::TestCommon; require_git(2.6); require_mods(qw(DBD::SQLite Search::Xapian)); -which('xapian-compact') or +have_xapian_compact or plan skip_all => 'xapian-compact missing for '.__FILE__; use_ok 'PublicInbox::V2Writable'; diff --git a/t/indexlevels-mirror.t b/t/indexlevels-mirror.t index 291e0d2f..b12bd3cb 100644 --- a/t/indexlevels-mirror.t +++ b/t/indexlevels-mirror.t @@ -6,13 +6,11 @@ use Test::More; use PublicInbox::Eml; use PublicInbox::Inbox; use PublicInbox::InboxWritable; -use PublicInbox::Spawn qw(which); require PublicInbox::Admin; use PublicInbox::TestCommon; my $PI_TEST_VERSION = $ENV{PI_TEST_VERSION} || 2; require_git('2.6') if $PI_TEST_VERSION == 2; require_mods(qw(DBD::SQLite)); -my $have_xapian_compact = which($ENV{XAPIAN_COMPACT} || 'xapian-compact'); my $mime = PublicInbox::Eml->new(<<'EOF'); From: a@example.com @@ -43,7 +41,7 @@ my $import_index_incremental = sub { # index master (required for v1) my @cmd = (qw(-index -j0), $ibx->{inboxdir}, "-L$level"); - push @cmd, '-c' if $have_xapian_compact; + push @cmd, '-c' if have_xapian_compact; ok(run_script(\@cmd, undef, { 2 => \$err }), 'index master'); my $ro_master = PublicInbox::Inbox->new({ inboxdir => $ibx->{inboxdir}, @@ -164,7 +162,7 @@ my $import_index_incremental = sub { 'indexlevel detectable by Admin '.$v.$level); SKIP: { - skip 'xapian-compact missing', 1 if !$have_xapian_compact; + skip 'xapian-compact missing', 1 if have_xapian_compact; my $cmd = [ qw(-compact), $mirror ]; ok(run_script($cmd, undef, { 2 => \$err}), "compact $level"); } diff --git a/t/nntpd.t b/t/nntpd.t index 14db1a93..c7a7ee6b 100644 --- a/t/nntpd.t +++ b/t/nntpd.t @@ -349,7 +349,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000 # -compact requires Xapian SKIP: { require_mods('Search::Xapian', 2); - which('xapian-compact') or skip 'xapian-compact missing', 2; + have_xapian_compact or skip 'xapian-compact missing', 2; is(xsys(qw(git config), "--file=$home/.public-inbox/config", "publicinbox.$group.indexlevel", 'medium'), 0, 'upgraded indexlevel'); diff --git a/t/xcpdb-reshard.t b/t/xcpdb-reshard.t index c1af5d9a..ede736c1 100644 --- a/t/xcpdb-reshard.t +++ b/t/xcpdb-reshard.t @@ -45,7 +45,7 @@ my %nums = map {; "$_->{num}" => 1 } @$orig; for my $R (qw(2 4 1 3 3)) { delete $ibx->{search}; # release old handles my $cmd = [@xcpdb, "-R$R", $ibx->{inboxdir}]; - push @$cmd, '--compact' if $R == 1; + push @$cmd, '--compact' if $R == 1 && have_xapian_compact; ok(run_script($cmd), "xcpdb -R$R"); my @new_shards = grep(m!/\d+\z!, glob("$ibx->{inboxdir}/xap*/*")); is(scalar(@new_shards), $R, 'resharded to two shards');