+
+ my ($min, $max) = $ibx->mm->minmax;
+ is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
+}
+
+
+# An incremental indexing test
+ok(unlink "$inboxdir/msgmap.sqlite3", 'remove msgmap');
+remove_tree($xap);
+ok(!-d $xap, 'Xapian directories removed again');
+{
+ my @warn;
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+ my %config = %$ibx_config;
+ my $ibx = PublicInbox::Inbox->new(\%config);
+ # mark1 4 simple additions in the same index_sync
+ $ibx->{ref_head} = $mark1;
+ my $im = PublicInbox::V2Writable->new($ibx);
+ eval { $im->index_sync() };
+ is($@, '', 'no error from reindexing without msgmap');
+ is_deeply(\@warn, [], 'no warnings');
+ $im->done;
+ my ($min, $max) = $ibx->mm->minmax;
+ is($min, 1, 'min as expected');
+ is($max, 4, 'max as expected');
+ is($ibx->mm->num_highwater, 4, 'num_highwater as expected');
+ is_deeply($ibx->mm->msg_range(\$min, $max),
+ [
+ [1, '1@example.com' ],
+ [2, '2@example.com' ],
+ [3, '3@example.com' ],
+ [4, '4@example.com' ],
+ ], 'msgmap as expected' );
+}
+{
+ my @warn;
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+ my %config = %$ibx_config;
+ my $ibx = PublicInbox::Inbox->new(\%config);
+ # mark2 A delete separated from an add in the same index_sync
+ $ibx->{ref_head} = $mark2;
+ my $im = PublicInbox::V2Writable->new($ibx);
+ eval { $im->index_sync() };
+ is($@, '', 'no error from reindexing without msgmap');
+ is_deeply(\@warn, [], 'no warnings');
+ $im->done;
+ my ($min, $max) = $ibx->mm->minmax;
+ is($min, 1, 'min as expected');
+ is($max, 3, 'max as expected');
+ is($ibx->mm->num_highwater, 4, 'num_highwater as expected');
+ is_deeply($ibx->mm->msg_range(\$min, $max),
+ [
+ [1, '1@example.com' ],
+ [2, '2@example.com' ],
+ [3, '3@example.com' ],
+ ], 'msgmap as expected' );
+}
+{
+ my @warn;
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+ my %config = %$ibx_config;
+ my $ibx = PublicInbox::Inbox->new(\%config);
+ # mark3 adds following the delete at mark2
+ $ibx->{ref_head} = $mark3;
+ my $im = PublicInbox::V2Writable->new($ibx);
+ eval { $im->index_sync() };
+ is($@, '', 'no error from reindexing without msgmap');
+ is_deeply(\@warn, [], 'no warnings');
+ $im->done;
+ my ($min, $max) = $ibx->mm->minmax;
+ is($min, 1, 'min as expected');
+ is($max, 10, 'max as expected');
+ is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
+ is_deeply($ibx->mm->msg_range(\$min, $max),
+ [
+ [1, '1@example.com' ],
+ [2, '2@example.com' ],
+ [3, '3@example.com' ],
+ [5, '5@example.com' ],
+ [6, '6@example.com' ],
+ [7, '7@example.com' ],
+ [8, '8@example.com' ],
+ [9, '9@example.com' ],
+ [10, '10@example.com' ],
+ ], 'msgmap as expected' );
+}
+{
+ my @warn;
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+ my %config = %$ibx_config;
+ my $ibx = PublicInbox::Inbox->new(\%config);
+ # mark4 A delete of an older message
+ $ibx->{ref_head} = $mark4;
+ my $im = PublicInbox::V2Writable->new($ibx);
+ eval { $im->index_sync() };
+ is($@, '', 'no error from reindexing without msgmap');
+ is_deeply(\@warn, [], 'no warnings');
+ $im->done;
+ my ($min, $max) = $ibx->mm->minmax;
+ is($min, 1, 'min as expected');
+ is($max, 10, 'max as expected');
+ is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
+ is_deeply($ibx->mm->msg_range(\$min, $max),
+ [
+ [1, '1@example.com' ],
+ [2, '2@example.com' ],
+ [3, '3@example.com' ],
+ [6, '6@example.com' ],
+ [7, '7@example.com' ],
+ [8, '8@example.com' ],
+ [9, '9@example.com' ],
+ [10, '10@example.com' ],
+ ], 'msgmap as expected' );
+}
+
+
+# Another incremental indexing test
+ok(unlink "$inboxdir/msgmap.sqlite3", 'remove msgmap');
+remove_tree($xap);
+ok(!-d $xap, 'Xapian directories removed again');
+{
+ my @warn;
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+ my %config = %$ibx_config;
+ my $ibx = PublicInbox::Inbox->new(\%config);
+ # mark2 an add and it's delete in the same index_sync
+ $ibx->{ref_head} = $mark2;
+ my $im = PublicInbox::V2Writable->new($ibx);
+ eval { $im->index_sync() };
+ is($@, '', 'no error from reindexing without msgmap');
+ is_deeply(\@warn, [], 'no warnings');
+ $im->done;
+ my ($min, $max) = $ibx->mm->minmax;
+ is($min, 1, 'min as expected');
+ is($max, 3, 'max as expected');
+ is($ibx->mm->num_highwater, 4, 'num_highwater as expected');
+ is_deeply($ibx->mm->msg_range(\$min, $max),
+ [
+ [1, '1@example.com' ],
+ [2, '2@example.com' ],
+ [3, '3@example.com' ],
+ ], 'msgmap as expected' );
+}
+{
+ my @warn;
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+ my %config = %$ibx_config;
+ my $ibx = PublicInbox::Inbox->new(\%config);
+ # mark3 adds following the delete at mark2
+ $ibx->{ref_head} = $mark3;
+ my $im = PublicInbox::V2Writable->new($ibx);
+ eval { $im->index_sync() };
+ is($@, '', 'no error from reindexing without msgmap');
+ is_deeply(\@warn, [], 'no warnings');
+ $im->done;
+ my ($min, $max) = $ibx->mm->minmax;
+ is($min, 1, 'min as expected');
+ is($max, 10, 'max as expected');
+ is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
+ is_deeply($ibx->mm->msg_range(\$min, $max),
+ [
+ [1, '1@example.com' ],
+ [2, '2@example.com' ],
+ [3, '3@example.com' ],
+ [5, '5@example.com' ],
+ [6, '6@example.com' ],
+ [7, '7@example.com' ],
+ [8, '8@example.com' ],
+ [9, '9@example.com' ],
+ [10, '10@example.com' ],
+ ], 'msgmap as expected' );
+}
+{
+ my @warn;
+ local $SIG{__WARN__} = sub { push @warn, @_ };
+ my %config = %$ibx_config;
+ my $ibx = PublicInbox::Inbox->new(\%config);
+ # mark4 A delete of an older message
+ $ibx->{ref_head} = $mark4;
+ my $im = PublicInbox::V2Writable->new($ibx);
+ eval { $im->index_sync() };
+ is($@, '', 'no error from reindexing without msgmap');
+ is_deeply(\@warn, [], 'no warnings');
+ $im->done;
+ my ($min, $max) = $ibx->mm->minmax;
+ is($min, 1, 'min as expected');
+ is($max, 10, 'max as expected');
+ is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
+ is_deeply($ibx->mm->msg_range(\$min, $max),
+ [
+ [1, '1@example.com' ],
+ [2, '2@example.com' ],
+ [3, '3@example.com' ],
+ [6, '6@example.com' ],
+ [7, '7@example.com' ],
+ [8, '8@example.com' ],
+ [9, '9@example.com' ],
+ [10, '10@example.com' ],
+ ], 'msgmap as expected' );