X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fsearch-thr-index.t;h=62745dbce1d5122db18164999addb4902e43812e;hb=88c7c7c26b44ee4c1141fddb628a518b4d4d21a4;hp=6c6e4c57639dab2b63dc27d7d4e2ade0f8bc9143;hpb=031dcde21cd8dab5494d9715ba50d6a539e3fb42;p=public-inbox.git
diff --git a/t/search-thr-index.t b/t/search-thr-index.t
index 6c6e4c57..62745dbc 100644
--- a/t/search-thr-index.t
+++ b/t/search-thr-index.t
@@ -1,17 +1,23 @@
-# Copyright (C) 2017-2018 all contributors
+#!perl -w
+# Copyright (C) 2017-2021 all contributors
# License: AGPL-3.0+
use strict;
-use warnings;
+use v5.10.1;
use Test::More;
-use File::Temp qw/tempdir/;
-use Email::MIME;
-eval { require PublicInbox::SearchIdx; };
-plan skip_all => "Xapian missing for search" if $@;
-my $tmpdir = tempdir('pi-search-thr-index.XXXXXX', TMPDIR => 1, CLEANUP => 1);
+use PublicInbox::TestCommon;
+use PublicInbox::MID qw(mids);
+use PublicInbox::Eml;
+require_mods(qw(DBD::SQLite Search::Xapian));
+require PublicInbox::SearchIdx;
+require PublicInbox::Smsg;
+require PublicInbox::Inbox;
+use PublicInbox::Import;
+my ($tmpdir, $for_destroy) = tmpdir();
my $git_dir = "$tmpdir/a.git";
-is(0, system(qw(git init -q --bare), $git_dir), "git init (main)");
-my $rw = PublicInbox::SearchIdx->new($git_dir, 1);
+PublicInbox::Import::init_bare($git_dir);
+my $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
+my $rw = PublicInbox::SearchIdx->new($ibx, 1);
ok($rw, "search indexer created");
my $data = <<'EOF';
Subject: [RFC 00/14]
@@ -31,28 +37,81 @@ EOF
my $num = 0;
# nb. using internal API, fragile!
-my $xdb = $rw->_xdb_acquire;
-$xdb->begin_transaction;
+my $xdb = $rw->begin_txn_lazy;
my @mids;
foreach (reverse split(/\n\n/, $data)) {
$_ .= "\n";
- my $mime = Email::MIME->new(\$_);
+ my $mime = PublicInbox::Eml->new(\$_);
$mime->header_set('From' => 'bw@g');
$mime->header_set('To' => 'git@vger.kernel.org');
- my $bytes = bytes::length($mime->as_string);
- my $mid = $mime->header('Message-Id');
- my $doc_id = $rw->add_message($mime, $bytes, ++$num, 'ignored', $mid);
+ my $bytes = length($mime->as_string);
+ my $mid = mids($mime->header_obj)->[0];
+ my $smsg = bless {
+ bytes => $bytes,
+ num => ++$num,
+ mid => $mid,
+ blob => '',
+ }, 'PublicInbox::Smsg';
+ my $doc_id = $rw->add_message($mime, $smsg);
push @mids, $mid;
ok($doc_id, 'message added: '. $mid);
}
my $prev;
+my %tids;
+my $dbh = $rw->{oidx}->dbh;
foreach my $mid (@mids) {
- my $res = $rw->get_thread($mid);
- is(3, $res->{total}, "got all messages from $mid");
+ my $msgs = $rw->{oidx}->get_thread($mid);
+ is(3, scalar(@$msgs), "got all messages from $mid");
+ foreach my $m (@$msgs) {
+ my $tid = $dbh->selectrow_array(<<'', undef, $m->{num});
+SELECT tid FROM over WHERE num = ? LIMIT 1
+
+ $tids{$tid}++;
+ }
+}
+
+is(scalar keys %tids, 1, 'all messages have the same tid');
+
+$rw->commit_txn_lazy;
+
+$xdb = $rw->begin_txn_lazy;
+{
+ my $mime = PublicInbox::Eml->new(<<'');
+Subject: [RFC 00/14]
+Message-Id: <1-bw@g>
+From: bw@g
+To: git@vger.kernel.org
+
+ my $dbh = $rw->{oidx}->dbh;
+ my ($id, $prev);
+ my $reidx = $rw->{oidx}->next_by_mid('1-bw@g', \$id, \$prev);
+ ok(defined $reidx);
+ my $num = $reidx->{num};
+ my $tid0 = $dbh->selectrow_array(<<'', undef, $num);
+SELECT tid FROM over WHERE num = ? LIMIT 1
+
+ my $bytes = length($mime->as_string);
+ my $mid = mids($mime->header_obj)->[0];
+ my $smsg = bless {
+ bytes => $bytes,
+ num => $num,
+ mid => $mid,
+ blob => '',
+ }, 'PublicInbox::Smsg';
+ my $doc_id = $rw->add_message($mime, $smsg);
+ ok($doc_id, 'message reindexed'. $mid);
+ is($doc_id, $num, "article number unchanged: $num");
+
+ my $tid1 = $dbh->selectrow_array(<<'', undef, $num);
+SELECT tid FROM over WHERE num = ? LIMIT 1
+
+ is($tid1, $tid0, 'tid unchanged on reindex');
}
+$rw->commit_txn_lazy;
+
done_testing();
1;