close $null;
[ 200, [ qw(Content-Type application/octet-stream) ]];
});
+ } elsif ($path eq '/pid') {
+ $code = 200;
+ push @$body, $$;
}
[ $code, $h, $body ]
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: $!';
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');
}
{
$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;
$! = 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);
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);
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;