]> Sergey Matveev's repositories - public-inbox.git/commitdiff
t/*.t: disable nntpd/httpd worker processes in most tests
authorEric Wong <e@80x24.org>
Mon, 4 Nov 2019 03:01:37 +0000 (03:01 +0000)
committerEric Wong <e@80x24.org>
Fri, 8 Nov 2019 20:23:53 +0000 (20:23 +0000)
And explicitly test for respawning in t/httpd-corner.t

There's no need to have an extra entries in the process table
for most tests we run, since that's not what we're testing.

t/httpd-corner.psgi
t/httpd-corner.t
t/httpd.t
t/v2mirror.t
t/v2writable.t
t/www_listing.t

index 5628f4abd5c92002abc48bd971a35f88454ab59a..bf38d1ff7995ddf1c8ee2447ccf1c956147f9419 100644 (file)
@@ -85,6 +85,9 @@ my $app = sub {
                        close $null;
                        [ 200, [ qw(Content-Type application/octet-stream) ]];
                });
+       } elsif ($path eq '/pid') {
+               $code = 200;
+               push @$body, $$;
        }
 
        [ $code, $h, $body ]
index 13c0c2db19e9cd40b8b542c111229e0f028e1c50..75573c3ef23a423a1238320b2b70cea592834a19 100644 (file)
@@ -28,7 +28,7 @@ my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
 my $httpd = 'blib/script/public-inbox-httpd';
 my $psgi = "./t/httpd-corner.psgi";
-my $sock = tcp_server();
+my $sock = tcp_server() or die;
 
 # make sure stdin is not a pipe for lsof test to check for leaking pipes
 open(STDIN, '<', '/dev/null') or die 'no /dev/null: $!';
@@ -63,9 +63,22 @@ my $spawn_httpd = sub {
        ok(defined $pid, 'forked httpd process successfully');
 };
 
-{
-       ok($sock, 'sock created');
-       $spawn_httpd->('-W0');
+$spawn_httpd->();
+if ('test worker death') {
+       my $conn = conn_for($sock, 'killed worker');
+       $conn->write("GET /pid HTTP/1.0\r\n\r\n");
+       ok($conn->read(my $buf, 8192), 'read response');
+       my ($head, $body) = split(/\r\n\r\n/, $buf);
+       like($body, qr/\A[0-9]+\z/, '/pid response');
+       my $pid = $body;
+       is(kill('KILL', $pid), 1, 'killed worker');
+
+       $conn = conn_for($sock, 'respawned worker');
+       $conn->write("GET /pid HTTP/1.0\r\n\r\n");
+       ok($conn->read($buf, 8192), 'read response');
+       ($head, $body) = split(/\r\n\r\n/, $buf);
+       like($body, qr/\A[0-9]+\z/, '/pid response');
+       isnt($body, $pid, 'respawned worker');
 }
 
 {
index 1340a7b3c02bb2003b0737cae4b0fe7809187155..15984a78e6d37901e0112d01de4dd8b10e27ce70 100644 (file)
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -53,7 +53,7 @@ EOF
                $im->done($mime);
        }
        ok($sock, 'sock created');
-       my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err" ];
+       my $cmd = [ $httpd, '-W0', "--stdout=$out", "--stderr=$err" ];
        $pid = spawn_listener(undef, $cmd, [$sock]);
        my $host = $sock->sockhost;
        my $port = $sock->sockport;
index a097a7f3a2cd0da80f109ec098210c034d0eef43..f826775cd5d52b013748850c4bdcedf2f7165c13 100644 (file)
@@ -66,7 +66,8 @@ END { kill 'TERM', $pid if defined $pid };
 $! = 0;
 $sock = tcp_server();
 ok($sock, 'sock created');
-my $cmd = [ "$script-httpd", "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ];
+my $httpd = "$script-httpd";
+my $cmd = [ $httpd, '-W0', "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ];
 ok(defined($pid = spawn_listener(undef, $cmd, [ $sock ])),
        'spawned httpd process successfully');
 my ($host, $port) = ($sock->sockhost, $sock->sockport);
index bfe17d0a843a7b33ec4b17c1c3079c042cc312b2..28420bb92419a4259707cae1cf4a67d8bf292aa9 100644 (file)
@@ -167,7 +167,7 @@ EOF
        my $len;
        END { kill 'TERM', $pid if defined $pid };
        my $nntpd = 'blib/script/public-inbox-nntpd';
-       my $cmd = [ $nntpd, "--stdout=$out", "--stderr=$err" ];
+       my $cmd = [ $nntpd, '-W0', "--stdout=$out", "--stderr=$err" ];
        $pid = spawn_listener({ PI_CONFIG => $pi_config }, $cmd, [ $sock ]);
        my $host_port = $sock->sockhost . ':' . $sock->sockport;
        my $n = Net::NNTP->new($host_port);
index 3d1b64ad4beea427592dfe29c5df5eb5ec622122..61a059e56cf7aa2b88046d8d81c5f757954d5ea9 100644 (file)
@@ -106,7 +106,7 @@ SKIP: {
 
        close $fh or die;
        my $env = { PI_CONFIG => $cfgfile };
-       my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err" ];
+       my $cmd = [ $httpd, '-W0', "--stdout=$out", "--stderr=$err" ];
        $pid = spawn_listener($env, $cmd, [$sock]);
        $sock = undef;