X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fmsgmap.t;h=a3b7200f16a566c39041f586c9fc9f97b665de3e;hb=7e4bd71efcf3bf61216ec1a7577e33be5f95b8a9;hp=20985ce8cb56be0b9d280660a75eaca6ac27739f;hpb=84d8920b92686e975929aebe845b6d4ea0a9ef0d;p=public-inbox.git
diff --git a/t/msgmap.t b/t/msgmap.t
index 20985ce8..a3b7200f 100644
--- a/t/msgmap.t
+++ b/t/msgmap.t
@@ -1,23 +1,19 @@
-# Copyright (C) 2015-2018 all contributors
+# Copyright (C) 2015-2021 all contributors
# License: AGPL-3.0+
use strict;
use warnings;
use Test::More;
-use File::Temp qw/tempdir/;
-
-foreach my $mod (qw(DBD::SQLite)) {
- eval "require $mod";
- plan skip_all => "$mod missing for nntpd.t" if $@;
-}
-
+use PublicInbox::TestCommon;
+require_mods('DBD::SQLite');
use_ok 'PublicInbox::Msgmap';
-my $tmpdir = tempdir('pi-msgmap-XXXXXX', TMPDIR => 1, CLEANUP => 1);
-my $d = PublicInbox::Msgmap->new($tmpdir, 1);
+my ($tmpdir, $for_destroy) = tmpdir();
+my $f = "$tmpdir/msgmap.sqlite3";
+my $d = PublicInbox::Msgmap->new_file($f, 1);
my %mid2num;
my %num2mid;
my @mids = qw(a@b c@d e@f g@h aa@bb aa@cc);
-is_deeply([$d->minmax], [undef,undef], "empty min max on new DB");
+is_deeply([$d->minmax], [0,0], "zero min max on new DB");
foreach my $mid (@mids) {
my $n = $d->mid_insert($mid);
@@ -55,7 +51,7 @@ is($d->mid_delete('a@b') + 0, 0, 'delete again returns zero');
is(undef, $d->num_for('a@b'), 'num_for fails on deleted msg');
$d = undef;
-ok($d = PublicInbox::Msgmap->new($tmpdir, 1), 'idempotent DB creation');
+ok($d = PublicInbox::Msgmap->new_file($f, 1), 'idempotent DB creation');
my ($min, $max) = $d->minmax;
ok($min > 0, "article min OK");
ok($max > 0 && $max < 10, "article max OK");
@@ -65,8 +61,14 @@ my $orig = $d->mid_insert('spam@1');
$d->mid_delete('spam@1');
is($d->mid_insert('spam@2'), 1 + $orig, "last number not recycled");
-my $tmp = $d->tmp_clone;
+my $tmp = $d->tmp_clone($tmpdir);
is_deeply([$d->minmax], [$tmp->minmax], 'Cloned temporary DB matches');
ok($tmp->mid_delete('spam@2'), 'temporary DB is writable');
+is(eval {
+ $tmp->atfork_prepare;
+ $tmp->atfork_parent;
+ 'ok'
+}, 'ok', 'atfork_* work on tmp_clone');
+
done_testing();