]> Sergey Matveev's repositories - public-inbox.git/blob - t/v2dupindex.t
update copyrights for 2021
[public-inbox.git] / t / v2dupindex.t
1 #!perl -w
2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4
5 # we can index a message from a mirror which bypasses dedupe.
6 use strict;
7 use Test::More;
8 use PublicInbox::TestCommon;
9 require_git(2.6);
10 require_mods(qw(DBD::SQLite));
11 my ($tmpdir, $for_destroy) = tmpdir();
12 use_ok 'PublicInbox::Import';
13 use_ok 'PublicInbox::Git';
14 use_ok 'PublicInbox::InboxWritable';
15 my $ibx = PublicInbox::InboxWritable->new({
16         inboxdir => $tmpdir,
17         name => 'test-v2dupindex',
18         version => 2,
19         indexlevel => 'basic',
20         -primary_address => 'test@example.com',
21 }, { nproc => 1 });
22 $ibx->init_inbox(1);
23 my $v2w = $ibx->importer;
24 $v2w->add(eml_load('t/plack-qp.eml'));
25 $v2w->add(eml_load('t/mda-mime.eml'));
26 $v2w->done;
27
28 my $git0 = PublicInbox::Git->new("$tmpdir/git/0.git");
29 my $im = PublicInbox::Import->new($git0, undef, undef, $ibx);
30 $im->{path_type} = 'v2';
31 $im->{lock_path} = undef;
32
33 # bypass duplicate filters (->header_set is optional)
34 my $eml = eml_load('t/plack-qp.eml');
35 $eml->header_set('X-This-Is-Not-Checked-By-ContentHash', 'blah');
36 ok($im->add($eml), 'add seen message directly');
37 ok($im->add(eml_load('t/mda-mime.eml')), 'add another seen message directly');
38
39 ok($im->add(eml_load('t/iso-2202-jp.eml')), 'add another new message');
40 $im->done;
41
42 # mimic a fresh clone by dropping indices
43 my @sqlite = (glob("$tmpdir/*sqlite3*"), glob("$tmpdir/xap*/*sqlite3*"));
44 is(unlink(@sqlite), scalar(@sqlite), 'unlinked SQLite indices');
45 my @shards = glob("$tmpdir/xap*/?");
46 is(scalar(@shards), 0, 'no Xapian shards to drop');
47
48 my $rdr = { 2 => \(my $err = '') };
49 ok(run_script([qw(-index -Lbasic), $tmpdir], undef, $rdr), '-indexed');
50 my @n = $ibx->over->dbh->selectrow_array('SELECT COUNT(*) FROM over');
51 is_deeply(\@n, [ 3 ], 'identical message not re-indexed');
52 my $mm = $ibx->mm->{dbh}->selectall_arrayref(<<'');
53 SELECT num,mid FROM msgmap ORDER BY num ASC
54
55 is_deeply($mm, [
56         [ 1, 'qp@example.com' ],
57         [ 2, 'multipart-html-sucks@11' ],
58         [ 3, '199707281508.AAA24167@hoyogw.example' ]
59 ], 'msgmap omits redundant message');
60
61 done_testing;