about summary refs log tree commit homepage
path: root/t/v2writable.t
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-03 20:21:05 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-03 20:24:43 +0000
commit031dcde21cd8dab5494d9715ba50d6a539e3fb42 (patch)
tree172df048191ee4cb07388f8d0b2a1e7246552667 /t/v2writable.t
parentb212aee7e13c460b73a3632458ae96c39d9eac97 (diff)
downloadpublic-inbox-031dcde21cd8dab5494d9715ba50d6a539e3fb42.tar.gz
We can't rely on header order for Message-ID after all
since we fall back to existing MIDs if they exist and
are unseen.  This lets us use SearchMsg->mid to get the
MID we associated with the NNTP article number to ensure
all NNTP article lookups roundtrip correctly.
Diffstat (limited to 't/v2writable.t')
-rw-r--r--t/v2writable.t73
1 files changed, 73 insertions, 0 deletions
diff --git a/t/v2writable.t b/t/v2writable.t
index f95b2e74..bf8ae5e6 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -93,5 +93,78 @@ ok($im->add($mime), 'ordinary message added');
         ok($found[1]->{doc_id} > 0, 'doc_id is positive');
 }
 
+SKIP: {
+        use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
+        use Net::NNTP;
+        use IO::Socket;
+        use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
+        eval { require Danga::Socket };
+        skip "Danga::Socket missing $@", 2 if $@;
+        my $err = "$mainrepo/stderr.log";
+        my $out = "$mainrepo/stdout.log";
+        my %opts = (
+                LocalAddr => '127.0.0.1',
+                ReuseAddr => 1,
+                Proto => 'tcp',
+                Type => SOCK_STREAM,
+                Listen => 1024,
+        );
+        my $group = 'inbox.comp.test.v2writable';
+        my $pi_config = "$mainrepo/pi_config";
+        open my $fh, '>', $pi_config or die "open: $!\n";
+        print $fh <<EOF
+[publicinbox "test-v2writable"]
+        mainrepo = $mainrepo
+        version = 2
+        address = test\@example.com
+        newsgroup = $group
+EOF
+        ;
+        close $fh or die "close: $!\n";
+        my $sock = IO::Socket::INET->new(%opts);
+        ok($sock, 'sock created');
+        my $pid;
+        my $len;
+        END { kill 'TERM', $pid if defined $pid };
+        $! = 0;
+        my $fl = fcntl($sock, F_GETFD, 0);
+        ok(! $!, 'no error from fcntl(F_GETFD)');
+        is($fl, FD_CLOEXEC, 'cloexec set by default (Perl behavior)');
+        $pid = fork;
+        if ($pid == 0) {
+                use POSIX qw(dup2);
+                $ENV{PI_CONFIG} = $pi_config;
+                # pretend to be systemd
+                fcntl($sock, F_SETFD, $fl &= ~FD_CLOEXEC);
+                dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
+                $ENV{LISTEN_PID} = $$;
+                $ENV{LISTEN_FDS} = 1;
+                my $nntpd = 'blib/script/public-inbox-nntpd';
+                exec $nntpd, "--stdout=$out", "--stderr=$err";
+                die "FAIL: $!\n";
+        }
+        ok(defined $pid, 'forked nntpd process successfully');
+        $! = 0;
+        fcntl($sock, F_SETFD, $fl |= FD_CLOEXEC);
+        ok(! $!, 'no error from fcntl(F_SETFD)');
+        my $host_port = $sock->sockhost . ':' . $sock->sockport;
+        my $n = Net::NNTP->new($host_port);
+        $n->group($group);
+        my $x = $n->xover('1-');
+        my %uniq;
+        foreach my $num (sort { $a <=> $b } keys %$x) {
+                my $mid = $x->{$num}->[3];
+                is($uniq{$mid}++, 0, "MID for $num is unique in XOVER");
+                is_deeply($n->xhdr('Message-ID', $num),
+                         { $num => $mid }, "XHDR lookup OK on num $num");
+                is_deeply($n->xhdr('Message-ID', $mid),
+                         { $mid => $mid }, "XHDR lookup OK on MID $num");
+        }
+        my %nn;
+        foreach my $mid (@{$n->newnews(0, $group)}) {
+                is($nn{$mid}++, 0, "MID is unique in NEWNEWS");
+        }
+        is_deeply([sort keys %nn], [sort keys %uniq]);
+};
 
 done_testing();