]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/v2writable.t
No ext_urls
[public-inbox.git] / t / v2writable.t
index 217eaf977ab526bc60ec1d5f9738cadb91615edb..0d1022047d49b8853a8e6a9370e3b960c5efde95 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
@@ -17,6 +17,7 @@ my $ibx = {
        inboxdir => $inboxdir,
        name => 'test-v2writable',
        version => 2,
+       -no_fsync => 1,
        -primary_address => 'test@example.com',
 };
 $ibx = PublicInbox::Inbox->new($ibx);
@@ -124,15 +125,14 @@ if ('ensure git configs are correct') {
 SELECT COUNT(*) FROM over WHERE num > 0
 
        is($ibx->mm->num_highwater, $total, 'got expected highwater value');
-       my $srch = $ibx->search;
-       my $mset1 = $srch->reopen->query('m:abcde@1', { mset => 1 });
+       my $mset1 = $ibx->search->reopen->mset('m:abcde@1');
        is($mset1->size, 1, 'message found by first MID');
-       my $mset2 = $srch->reopen->query('m:abcde@2', { mset => 1 });
+       my $mset2 = $ibx->search->mset('m:abcde@2');
        is($mset2->size, 1, 'message found by second MID');
        is((($mset1->items)[0])->get_docid, (($mset2->items)[0])->get_docid,
                'same document') if ($mset1->size);
 
-       my $alt = $srch->reopen->query('m:alt-id-for-nntp', { mset => 1 });
+       my $alt = $ibx->search->mset('m:alt-id-for-nntp');
        is($alt->size, 1, 'message found by alt MID (NNTP)');
        is((($alt->items)[0])->get_docid, (($mset1->items)[0])->get_docid,
                'same document') if ($mset1->size);
@@ -149,7 +149,7 @@ SELECT COUNT(*) FROM over WHERE num > 0
 }
 
 {
-       use Net::NNTP;
+       require_mods('Net::NNTP', 1);
        my $err = "$inboxdir/stderr.log";
        my $out = "$inboxdir/stdout.log";
        my $group = 'inbox.comp.test.v2writable';
@@ -165,12 +165,11 @@ EOF
        ;
        close $fh or die "close: $!\n";
        my $sock = tcp_server();
-       ok($sock, 'sock created');
        my $len;
        my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ];
        my $env = { PI_CONFIG => $pi_config };
        my $td = start_script($cmd, $env, { 3 => $sock });
-       my $host_port = $sock->sockhost . ':' . $sock->sockport;
+       my $host_port = tcp_host_port($sock);
        my $n = Net::NNTP->new($host_port);
        $n->group($group);
        my $x = $n->xover('1-');
@@ -231,8 +230,7 @@ EOF
        my $num = $smsg->{num};
        like($num, qr/\A\d+\z/, 'numeric number in return message');
        is($ibx->mm->mid_for($num), undef, 'no longer in Msgmap by num');
-       my $srch = $ibx->search->reopen;
-       my $mset = $srch->query('m:'.$mid, { mset => 1});
+       my $mset = $ibx->search->reopen->mset('m:'.$mid);
        is($mset->size, 0, 'no longer found in Xapian');
        my @log1 = (@log, qw(-1 --pretty=raw --raw -r --no-renames));
        is($ibx->over->get_art($num), undef,
@@ -257,8 +255,8 @@ EOF
 {
        ok($im->add($mime), 'add message to be purged');
        local $SIG{__WARN__} = sub {};
-       ok(my $cmts = $im->purge($mime), 'purged message');
-       like($cmts->[0], qr/\A[a-f0-9]{40}\z/, 'purge returned current commit');
+       ok(my $cmt = $im->purge($mime), 'purged message');
+       like($cmt->[0], qr/\A[a-f0-9]{40,}\z/, 'purge returned current commit');
        $im->done;
 
        # again
@@ -276,14 +274,29 @@ EOF
        $mime->header_set('Message-ID', "<$y>");
        $mime->header_set('References', "<$x>");
        ok($im->add($mime), 'add excessively long References');
-       $im->barrier;
+       $im->done;
 
        my $msgs = $ibx->over->get_thread('x'x244);
        is(2, scalar(@$msgs), 'got both messages');
        is($msgs->[0]->{mid}, 'x'x244, 'stored truncated mid');
        is($msgs->[1]->{references}, '<'.('x'x244).'>', 'stored truncated ref');
        is($msgs->[1]->{mid}, 'y'x244, 'stored truncated mid(2)');
+}
+
+if ('UTF-8 References') {
+       my @w;
+       local $SIG{__WARN__} = sub { push @w, @_ };
+       my $msg = <<EOM;
+From: a\@example.com
+Subject: b
+Message-ID: <horrible\@example>
+References: <\xc4\x80\@example>
+
+EOM
+       ok($im->add(PublicInbox::Eml->new($msg."a\n")), 'UTF-8 References 1');
+       ok($im->add(PublicInbox::Eml->new($msg."b\n")), 'UTF-8 References 2');
        $im->done;
+       ok(!grep(/Wide character/, @w), 'no wide characters') or xbail(\@w);
 }
 
 my $tmp = {
@@ -311,7 +324,7 @@ ok($@, 'V2Writable fails on non-existent dir');
        open $fh, '<', $alt or die $!;
        my $before = do { local $/; <$fh> };
 
-       ok($v2w->git_init(3), 'init a new epoch');
+       ok($v2w->{mg}->add_epoch(3), 'init a new epoch');
        open $fh, '<', $alt or die $!;
        my $after = do { local $/; <$fh> };
        ok(index($after, $before) > 0,