1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::ContentId qw(content_digest);
8 use File::Temp qw/tempdir/;
9 use File::Path qw(remove_tree);
11 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
13 plan skip_all => "$mod missing for v2reindex.t" if $@;
15 use_ok 'PublicInbox::V2Writable';
16 my $mainrepo = tempdir('pi-v2reindex-XXXXXX', TMPDIR => 1, CLEANUP => 1);
18 mainrepo => $mainrepo,
19 name => 'test-v2writable',
21 -primary_address => 'test@example.com',
23 $ibx = PublicInbox::Inbox->new($ibx);
24 my $mime = PublicInbox::MIME->create(
26 From => 'a@example.com',
27 To => 'test@example.com',
28 Subject => 'this is a subject',
29 Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
31 body => "hello world\n",
33 local $ENV{NPROC} = 2;
34 my $im = PublicInbox::V2Writable->new($ibx, 1);
35 foreach my $i (1..10) {
36 $mime->header_set('Message-Id', "<$i\@example.com>");
37 ok($im->add($mime), "message $i added");
43 if ('test remove later') {
44 $mime->header_set('Message-Id', "<5\@example.com>");
49 my $minmax = [ $ibx->mm->minmax ];
50 ok(defined $minmax->[0] && defined $minmax->[1], 'minmax defined');
52 eval { $im->index_sync({reindex => 1}) };
53 is($@, '', 'no error from reindexing');
56 my $xap = "$mainrepo/xap".PublicInbox::Search::SCHEMA_VERSION();
58 ok(!-d $xap, 'Xapian directories removed');
59 eval { $im->index_sync({reindex => 1}) };
60 is($@, '', 'no error from reindexing');
62 ok(-d $xap, 'Xapian directories recreated');
65 is_deeply($minmax, [ $ibx->mm->minmax ], 'minmax unchanged');
67 ok(unlink "$mainrepo/msgmap.sqlite3", 'remove msgmap');
69 ok(!-d $xap, 'Xapian directories removed again');
72 local $SIG{__WARN__} = sub { push @warn, @_ };
73 eval { $im->index_sync({reindex => 1}) };
74 is($@, '', 'no error from reindexing without msgmap');
75 is(scalar(@warn), 0, 'no warnings from reindexing');
77 ok(-d $xap, 'Xapian directories recreated');
79 is_deeply($minmax, [ $ibx->mm->minmax ], 'minmax unchanged');
82 ok(unlink "$mainrepo/msgmap.sqlite3", 'remove msgmap');
84 ok(!-d $xap, 'Xapian directories removed again');
87 local $SIG{__WARN__} = sub { push @warn, @_ };
88 eval { $im->index_sync({reindex => 1}) };
89 is($@, '', 'no error from reindexing without msgmap');
90 is_deeply(\@warn, [], 'no warnings');
92 ok(-d $xap, 'Xapian directories recreated');
94 is_deeply($minmax, [ $ibx->mm->minmax ], 'minmax unchanged');