]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/perf-nntpd.t
config: support "inboxdir" in addition to "mainrepo"
[public-inbox.git] / t / perf-nntpd.t
index 4987f98109b1c9e284bd6052daafbb69099f28db..7abf2249ef32386ad7677fff22272b2e417d216e 100644 (file)
@@ -1,18 +1,18 @@
-# Copyright (C) 2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
 use Test::More;
-use Benchmark qw(:all);
+use Benchmark qw(:all :hireswallclock);
 use PublicInbox::Inbox;
 use File::Temp qw/tempdir/;
-use POSIX qw(dup2);
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
 use Net::NNTP;
 my $pi_dir = $ENV{GIANT_PI_DIR};
 plan skip_all => "GIANT_PI_DIR not defined for $0" unless $pi_dir;
 eval { require PublicInbox::Search };
 my ($host_port, $group, %opts, $s, $pid);
+require './t/common.perl';
+
 END {
        if ($s) {
                $s->print("QUIT\r\n");
@@ -27,7 +27,7 @@ if (($ENV{NNTP_TEST_URL} || '') =~ m!\Anntp://([^/]+)/([^/]+)\z!) {
        $host_port .= ":119" unless index($host_port, ':') > 0;
 } else {
        $group = 'inbox.test.perf.nntpd';
-       my $ibx = { mainrepo => $pi_dir, newsgroup => $group };
+       my $ibx = { inboxdir => $pi_dir, newsgroup => $group };
        $ibx = PublicInbox::Inbox->new($ibx);
        my $nntpd = 'blib/script/public-inbox-nntpd';
        my $tmpdir = tempdir('perf-nntpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
@@ -38,36 +38,16 @@ if (($ENV{NNTP_TEST_URL} || '') =~ m!\Anntp://([^/]+)/([^/]+)\z!) {
                print $fh <<"" or die "print $pi_config: $!";
 [publicinbox "test"]
        newsgroup = $group
-       mainrepo = $pi_dir
+       inboxdir = $pi_dir
        address = test\@example.com
 
                close $fh or die "close($pi_config): $!";
        }
 
-       %opts = (
-               LocalAddr => '127.0.0.1',
-               ReuseAddr => 1,
-               Proto => 'tcp',
-               Listen => 1024,
-       );
-       my $sock = IO::Socket::INET->new(%opts);
-
+       my $sock = tcp_server();
        ok($sock, 'sock created');
-       $! = 0;
-       $pid = fork;
-       if ($pid == 0) {
-               # pretend to be systemd
-               my $fl = fcntl($sock, F_GETFD, 0);
-               dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
-               dup2(1, 2) or die "dup2 failed: $!\n";
-               fcntl($sock, F_SETFD, $fl &= ~FD_CLOEXEC);
-               $ENV{LISTEN_PID} = $$;
-               $ENV{LISTEN_FDS} = 1;
-               $ENV{PI_CONFIG} = $pi_config;
-               exec $nntpd, '-W0';
-               die "FAIL: $!\n";
-       }
-       ok(defined $pid, 'forked nntpd process successfully');
+       my $cmd = [ $nntpd, '-W0' ];
+       $pid = spawn_listener({ PI_CONFIG => $pi_config }, $cmd, [$sock]);
        $host_port = $sock->sockhost . ':' . $sock->sockport;
 }
 %opts = (
@@ -78,9 +58,14 @@ if (($ENV{NNTP_TEST_URL} || '') =~ m!\Anntp://([^/]+)/([^/]+)\z!) {
 $s = IO::Socket::INET->new(%opts);
 $s->autoflush(1);
 my $buf = $s->getline;
-is($buf, "201 server ready - post via email\r\n", 'got greeting');
-ok($s->print("GROUP $group\r\n"), 'changed group');
-$buf = $s->getline;
+like($buf, qr/\A201 .* ready - post via email\r\n/s, 'got greeting');
+
+my $t = timeit(10, sub {
+       ok($s->print("GROUP $group\r\n"), 'changed group');
+       $buf = $s->getline;
+});
+diag 'GROUP took: ' . timestr($t);
+
 my ($tot, $min, $max) = ($buf =~ /\A211 (\d+) (\d+) (\d+) /);
 ok($tot && $min && $max, 'got GROUP response');
 my $nr = $max - $min;
@@ -100,7 +85,7 @@ sub read_until_dot ($) {
        $n;
 }
 
-my $t = timeit(1, sub {
+$t = timeit(1, sub {
        $s->print("XOVER $spec\r\n");
        $n = read_until_dot($s);
 });
@@ -116,7 +101,7 @@ diag "XHDR From ". timestr($t) . " for $n";
 my $date = $ENV{NEWNEWS_DATE};
 unless ($date) {
        my (undef, undef, undef, $d, $m, $y) = gmtime(time - 30 * 86400);
-       $date = sprintf('%04u%02u%02u', $y + 1900, $m, $d);
+       $date = sprintf('%04u%02u%02u', $y + 1900, $m + 1, $d);
        diag "NEWNEWS_DATE undefined, using $date";
 }
 $t = timeit(1, sub {