1 # Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use Benchmark qw(:all :hireswallclock);
7 use PublicInbox::Inbox;
9 my $inboxdir = $ENV{GIANT_INBOX_DIR} // $ENV{GIANT_PI_DIR};
10 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless defined($inboxdir);
11 my ($host_port, $group, %opts, $s, $td, $tmp_obj);
12 use PublicInbox::TestCommon;
14 if (($ENV{NNTP_TEST_URL} || '') =~ m!\Anntp://([^/]+)/([^/]+)\z!) {
15 ($host_port, $group) = ($1, $2);
16 $host_port .= ":119" unless index($host_port, ':') > 0;
18 $group = 'inbox.test.perf.nntpd';
19 my $ibx = { inboxdir => $inboxdir, newsgroup => $group };
20 $ibx = PublicInbox::Inbox->new($ibx);
22 ($tmpdir, $tmp_obj) = tmpdir();
24 my $pi_config = "$tmpdir/config";
26 open my $fh, '>', $pi_config or die "open($pi_config): $!";
27 print $fh <<"" or die "print $pi_config: $!";
31 address = test\@example.com
33 close $fh or die "close($pi_config): $!";
36 my $sock = tcp_server();
37 ok($sock, 'sock created');
38 my $cmd = [ '-nntpd', '-W0' ];
39 $td = start_script($cmd, { PI_CONFIG => $pi_config }, { 3 => $sock });
40 $host_port = $sock->sockhost . ':' . $sock->sockport;
43 PeerAddr => $host_port,
47 $s = IO::Socket::INET->new(%opts);
49 my $buf = $s->getline;
50 like($buf, qr/\A201 .* ready - post via email\r\n/s, 'got greeting');
52 my $t = timeit(10, sub {
53 ok($s->print("GROUP $group\r\n"), 'changed group');
56 diag 'GROUP took: ' . timestr($t);
58 my ($tot, $min, $max) = ($buf =~ /\A211 (\d+) (\d+) (\d+) /);
59 ok($tot && $min && $max, 'got GROUP response');
62 my $nmin = $max - $nmax;
63 $nmin = $min if $nmin < $min;
65 my $spec = "$nmin-$max";
68 sub read_until_dot ($) {
73 } until $buf eq ".\r\n";
78 $s->print("XOVER $spec\r\n");
79 $n = read_until_dot($s);
81 diag 'xover took: ' . timestr($t) . " for $n";
84 $s->print("HDR From $spec\r\n");
85 $n = read_until_dot($s);
88 diag "XHDR From ". timestr($t) . " for $n";
90 my $date = $ENV{NEWNEWS_DATE};
92 my (undef, undef, undef, $d, $m, $y) = gmtime(time - 30 * 86400);
93 $date = sprintf('%04u%02u%02u', $y + 1900, $m + 1, $d);
94 diag "NEWNEWS_DATE undefined, using $date";
97 $s->print("NEWNEWS * $date 000000 GMT\r\n");
98 $n = read_until_dot($s);
100 diag 'newnews took: ' . timestr($t) . " for $n";
103 $s->print("QUIT\r\n");