From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 5/5] t/*.t: disable nntpd/httpd worker processes in most tests
Date: Mon, 4 Nov 2019 03:01:37 +0000 [thread overview]
Message-ID: <20191104030137.4301-6-e@80x24.org> (raw)
In-Reply-To: <20191104030137.4301-1-e@80x24.org>
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(-)
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;
prev parent reply other threads:[~2019-11-04 3:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-04 3:01 [PATCH 0/5] tiny test overhead reductions Eric Wong
2019-11-04 3:01 ` [PATCH 1/5] t/*.t: remove IPC::Run dependency for git commands Eric Wong
2019-11-04 3:01 ` [PATCH 2/5] t/httpd-corner.t: drop unnecessary bytes:: for length() Eric Wong
2019-11-04 3:01 ` [PATCH 3/5] t/httpd-corner.t: get rid of IPC::Run for running curl Eric Wong
2019-11-04 3:01 ` [PATCH 4/5] t/hl_mod.t: remove IPC::Run (and File::Temp) dependency Eric Wong
2019-11-04 3:01 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191104030137.4301-6-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).