From ad221e9b2852f6c57ec1692dafa786de60621bb6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 4 Nov 2019 03:01:37 +0000 Subject: t/*.t: disable nntpd/httpd worker processes in most tests 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 | 3 +++ t/httpd-corner.t | 21 +++++++++++++++++---- t/httpd.t | 2 +- t/v2mirror.t | 3 ++- t/v2writable.t | 2 +- t/www_listing.t | 2 +- 6 files changed, 25 insertions(+), 8 deletions(-) (limited to 't') diff --git a/t/httpd-corner.psgi b/t/httpd-corner.psgi index 5628f4ab..bf38d1ff 100644 --- a/t/httpd-corner.psgi +++ b/t/httpd-corner.psgi @@ -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 ] diff --git a/t/httpd-corner.t b/t/httpd-corner.t index 13c0c2db..75573c3e 100644 --- a/t/httpd-corner.t +++ b/t/httpd-corner.t @@ -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'); } { diff --git a/t/httpd.t b/t/httpd.t index 1340a7b3..15984a78 100644 --- 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; diff --git a/t/v2mirror.t b/t/v2mirror.t index a097a7f3..f826775c 100644 --- a/t/v2mirror.t +++ b/t/v2mirror.t @@ -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); diff --git a/t/v2writable.t b/t/v2writable.t index bfe17d0a..28420bb9 100644 --- a/t/v2writable.t +++ b/t/v2writable.t @@ -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); diff --git a/t/www_listing.t b/t/www_listing.t index 3d1b64ad..61a059e5 100644 --- a/t/www_listing.t +++ b/t/www_listing.t @@ -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; -- cgit v1.2.3-24-ge0c7