]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/search-thr-index.t
*idx: pass $smsg in more places instead of many args
[public-inbox.git] / t / search-thr-index.t
index 2aa97bffcb89580c6a205eeeff695c612457fec4..f073304a2a5bc1869255af9f180095e500a49ef4 100644 (file)
@@ -1,18 +1,22 @@
-# Copyright (C) 2017-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2017-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
+use bytes (); # only for bytes::length
 use Test::More;
-use File::Temp qw/tempdir/;
+use PublicInbox::TestCommon;
 use PublicInbox::MID qw(mids);
 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);
+require_mods(qw(DBD::SQLite Search::Xapian));
+require PublicInbox::SearchIdx;
+require PublicInbox::Smsg;
+require PublicInbox::Inbox;
+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);
+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]
@@ -42,15 +46,67 @@ foreach (reverse split(/\n\n/, $data)) {
        $mime->header_set('To' => 'git@vger.kernel.org');
        my $bytes = bytes::length($mime->as_string);
        my $mid = mids($mime->header_obj)->[0];
-       my $doc_id = $rw->add_message($mime, $bytes, ++$num, 'ignored', $mid);
+       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->{over}->connect;
 foreach my $mid (@mids) {
        my $msgs = $rw->{over}->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 = Email::MIME->new(<<'');
+Subject: [RFC 00/14]
+Message-Id: <1-bw@g>
+From: bw@g
+To: git@vger.kernel.org
+
+       my $dbh = $rw->{over}->connect;
+       my ($id, $prev);
+       my $reidx = $rw->{over}->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 = 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;