about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-16 22:31:22 +0000
committerEric Wong <e@yhbt.net>2020-06-21 00:43:28 +0000
commit0e6ceff37fc38f28a1520d7475f31d47f74ec7e6 (patch)
tree18b8e61fd60f10989b9cffff7417cef050d40e1c /t
parent3c947561fa0678803158f2174ff87992addb3c7e (diff)
downloadpublic-inbox-0e6ceff37fc38f28a1520d7475f31d47f74ec7e6.tar.gz
Having `git cat-file' as a separate process naturally lends
itself to asynchronous dispatch.  Our event loop for -nntpd no
longer blocks on slow git storage.

Pipelining in -imapd was tricky and bugs were exposed by
mbsync(1).  Update t/nntpd.t to support pipelining ARTICLE
requests to ensure we don't have the same problems -imapd
did during development.
Diffstat (limited to 't')
-rw-r--r--t/nntp.t12
-rw-r--r--t/nntpd.t20
2 files changed, 27 insertions, 5 deletions
diff --git a/t/nntp.t b/t/nntp.t
index 2a9f3a4f..1db896cf 100644
--- a/t/nntp.t
+++ b/t/nntp.t
@@ -109,9 +109,12 @@ use_ok 'PublicInbox::Inbox';
         my $mid = 'a@b';
         my $mime = PublicInbox::Eml->new("Message-ID: <$mid>\r\n\r\n");
         my $hdr = $mime->header_obj;
-        my $mock_self = { nntpd => { grouplist => [],
-                                     servername => 'example.com' } };
-        PublicInbox::NNTP::set_nntp_headers($mock_self, $hdr, $ng, 1, $mid);
+        my $mock_self = {
+                nntpd => { grouplist => [], servername => 'example.com' },
+                ng => $ng,
+        };
+        my $smsg = { num => 1, mid => $mid };
+        PublicInbox::NNTP::set_nntp_headers($mock_self, $hdr, $smsg);
         is_deeply([ $mime->header('Message-ID') ], [ "<$mid>" ],
                 'Message-ID unchanged');
         is_deeply([ $mime->header('Archived-At') ], [ "<${u}a\@b/>" ],
@@ -126,7 +129,8 @@ use_ok 'PublicInbox::Inbox';
                 'Xref: set');
 
         $ng->{-base_url} = 'http://mirror.example.com/m/';
-        PublicInbox::NNTP::set_nntp_headers($mock_self, $hdr, $ng, 2, $mid);
+        $smsg->{num} = 2;
+        PublicInbox::NNTP::set_nntp_headers($mock_self, $hdr, $smsg);
         is_deeply([ $mime->header('Message-ID') ], [ "<$mid>" ],
                 'Message-ID unchanged');
         is_deeply([ $mime->header('Archived-At') ],
diff --git a/t/nntpd.t b/t/nntpd.t
index b24720eb..c681b01c 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -12,6 +12,8 @@ use IO::Socket;
 use Socket qw(IPPROTO_TCP TCP_NODELAY);
 use Net::NNTP;
 use Sys::Hostname;
+use POSIX qw(_exit);
+use Digest::SHA;
 
 # FIXME: make easier to test both versions
 my $version = $ENV{PI_TEST_VERSION} || 1;
@@ -287,21 +289,37 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
         # pipelined requests:
         {
                 my $nreq = 90;
+                my $nart = 2;
                 syswrite($s, "GROUP $group\r\n");
                 my $res = <$s>;
                 my $rdr = fork;
                 if ($rdr == 0) {
-                        use POSIX qw(_exit);
                         for (1..$nreq) {
                                 <$s> =~ /\A224 / or _exit(1);
                                 <$s> =~ /\A1/ or _exit(2);
                                 <$s> eq ".\r\n" or _exit(3);
                         }
+                        my %sums;
+                        for (1..$nart) {
+                                <$s> =~ /\A220 / or _exit(4);
+                                my $dig = Digest::SHA->new(1);
+                                while (my $l = <$s>) {
+                                        last if $l eq ".\r\n";
+                                        $dig->add($l);
+                                }
+                                $dig = $dig->hexdigest;
+                                $sums{$dig}++;
+                        }
+                        if ($nart) {
+                                scalar(keys(%sums)) == 1 or _exit(5);
+                                (values(%sums))[0] == $nart or _exit(6);
+                        }
                         _exit(0);
                 }
                 for (1..$nreq) {
                         syswrite($s, "XOVER 1\r\n");
                 }
+                syswrite($s, "ARTICLE 1\r\n" x $nart);
                 is($rdr, waitpid($rdr, 0), 'reader done');
                 is($? >> 8, 0, 'no errors');
         }