]> Sergey Matveev's repositories - public-inbox.git/commitdiff
tests: consistently check for xapian-compact
authorEric Wong <e@yhbt.net>
Mon, 14 Sep 2020 06:29:26 +0000 (06:29 +0000)
committerEric Wong <e@80x24.org>
Mon, 14 Sep 2020 21:29:56 +0000 (21:29 +0000)
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
t/convert-compact.t
t/indexlevels-mirror.t
t/nntpd.t
t/xcpdb-reshard.t

index 428191791b5ff35788dc365804d477eeec6a58a9..299b9c6a830833966df288687270d27ae95e1b49 100644 (file)
@@ -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;
 
index 575262e8e5d3360b85825d686c39ba3835ae6e34..e479476d8589aac7be5a6f024febf31df9002682 100644 (file)
@@ -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';
index 291e0d2fc121c8f5dc2d3440580d13ca19aea86e..b12bd3cb2b177276cb01397ad660cf10dc9f571e 100644 (file)
@@ -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");
        }
index 14db1a93019771426635cecc8fafedd9d2c7c920..c7a7ee6bb3ad512a1ed0b12807ae93016a58be7d 100644 (file)
--- 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');
index c1af5d9a8f669ac53f25d00e925a9e928b651750..ede736c1524b5597cf0c151aa1b57b70c4ebd9a0 100644 (file)
@@ -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');