about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-05-07 10:49:00 +0000
committerEric Wong <e@80x24.org>2017-05-07 10:58:08 +0000
commitfeb4a75affbe5f940116dc4f6bcc5ddb52a110b4 (patch)
tree34ab1b914e7f458cfb08db3fa9eead980960bd3f /t
parentde243560e2caa1d19bcbf518edfaf8b016161245 (diff)
downloadpublic-inbox-feb4a75affbe5f940116dc4f6bcc5ddb52a110b4.tar.gz
Due to the asynchronous nature of SMTP, it is possible for the
root message of a thread (with no References/In-Reply-To)
to arrive last in a series.  We must preserve the thread_id
of the ghost message in this case, as we do when vivifiying
non-root ghosts.

Otherwise, this causes threads to be broken when the root
arrives last.
Diffstat (limited to 't')
-rw-r--r--t/search-thr-index.t58
1 files changed, 58 insertions, 0 deletions
diff --git a/t/search-thr-index.t b/t/search-thr-index.t
new file mode 100644
index 00000000..65495546
--- /dev/null
+++ b/t/search-thr-index.t
@@ -0,0 +1,58 @@
+# Copyright (C) 2017 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use warnings;
+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);
+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);
+ok($rw, "search indexer created");
+my $data = <<'EOF';
+Subject: [RFC 00/14]
+Message-Id: <1-bw@g>
+
+Subject: [RFC 09/14]
+Message-Id: <10-bw@g>
+In-Reply-To: <1-bw@g>
+References: <1-bw@g>
+
+Subject: [RFC 03/14]
+Message-Id: <4-bw@g>
+In-Reply-To: <1-bw@g>
+References: <1-bw@g>
+
+EOF
+
+my $num = 0;
+# nb. using internal API, fragile!
+my $xdb = $rw->_xdb_acquire;
+$xdb->begin_transaction;
+my @mids;
+
+foreach (reverse split(/\n\n/, $data)) {
+        $_ .= "\n";
+        my $mime = Email::MIME->new(\$_);
+        $mime->header_set('From' => 'bw@g');
+        $mime->header_set('To' => 'git@vger.kernel.org');
+        my $bytes = bytes::length($mime->as_string);
+        my $doc_id = $rw->add_message($mime, $bytes, ++$num, 'ignored');
+        my $mid = $mime->header('Message-Id');
+        push @mids, $mid;
+        ok($doc_id, 'message added: '. $mid);
+}
+
+my $prev;
+foreach my $mid (@mids) {
+        my $res = $rw->get_thread($mid);
+        is(3, $res->{total}, "got all messages from $mid");
+}
+
+done_testing();
+
+1;