diff options
author | Eric Wong <e@80x24.org> | 2019-12-12 21:16:49 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-12-14 21:13:51 +0000 |
commit | b93c7a7efed33c68a2cf229d3086d4edec082149 (patch) | |
tree | eba60a053e50ba62f80c8fb2f9b0bcf7b34703bf /t/httpd-unix.t | |
parent | ede8cc1c664e332cfa44bd22c36a31aac1a5fb13 (diff) | |
download | public-inbox-b93c7a7efed33c68a2cf229d3086d4edec082149.tar.gz |
This gets rid of the last "END{}" block in our code and cleans up a (temporary) circular reference. Furthermore, ensure the cleanup code still works in all configurations by adding tests and testing both the -W1 (default, 1 worker) and -W0 (no workers) code paths.
Diffstat (limited to 't/httpd-unix.t')
-rw-r--r-- | t/httpd-unix.t | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/t/httpd-unix.t b/t/httpd-unix.t index ceec127c..2c8f8d6b 100644 --- a/t/httpd-unix.t +++ b/t/httpd-unix.t @@ -22,7 +22,6 @@ my $td; my $spawn_httpd = sub { my (@args) = @_; - push @args, '-W0'; my $cmd = [ '-httpd', @args, "--stdout=$out", "--stderr=$err", $psgi ]; $td = start_script($cmd); }; @@ -36,7 +35,7 @@ my $spawn_httpd = sub { } ok(!-S $unix, 'UNIX socket does not exist, yet'); -$spawn_httpd->("-l$unix"); +$spawn_httpd->("-l$unix", '-W0'); my %o = (Peer => $unix, Type => SOCK_STREAM); for (1..1000) { last if -S $unix && IO::Socket::UNIX->new(%o); @@ -87,26 +86,28 @@ check_sock($unix); SKIP: { eval 'require Net::Server::Daemonize'; - skip('Net::Server missing for pid-file/daemonization test', 10) if $@; + skip('Net::Server missing for pid-file/daemonization test', 20) if $@; + my $pid_file = "$tmpdir/pid"; + for my $w (qw(-W0 -W1)) { + # wait for daemonization + $spawn_httpd->("-l$unix", '-D', '-P', $pid_file, $w); + $td->join; + is($?, 0, "daemonized $w process"); + check_sock($unix); - # wait for daemonization - $spawn_httpd->("-l$unix", '-D', '-P', "$tmpdir/pid"); - $td->join; - is($?, 0, 'daemonized process OK'); - check_sock($unix); - - ok(-f "$tmpdir/pid", 'pid file written'); - open my $fh, '<', "$tmpdir/pid" or die "open failed: $!"; - local $/ = "\n"; - my $rpid = <$fh>; - chomp $rpid; - like($rpid, qr/\A\d+\z/s, 'pid file looks like a pid'); - is(kill('TERM', $rpid), 1, 'signalled daemonized process'); - for (1..100) { - kill(0, $rpid) or last; - select undef, undef, undef, 0.02; + ok(-f $pid_file, "$w pid file written"); + open my $fh, '<', "$tmpdir/pid" or die "open failed: $!"; + my $rpid = do { local $/; <$fh> }; + chomp $rpid; + like($rpid, qr/\A\d+\z/s, "$w pid file looks like a pid"); + is(kill('TERM', $rpid), 1, "signaled daemonized $w process"); + for (1..100) { + kill(0, $rpid) or last; + select undef, undef, undef, 0.02; + } + is(kill(0, $rpid), 0, "daemonized $w process exited"); + ok(!-e $pid_file, "$w pid file unlinked at exit"); } - is(kill(0, $rpid), 0, 'daemonized process exited') } done_testing(); |