]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/httpd-https.t
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / t / httpd-https.t
index 22c62bf412034efce62cacb6a6e269ebb24be5c3..fcfa12afb04808740a8bd90ae9e5b490e19f22bb 100644 (file)
@@ -1,15 +1,12 @@
-# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
 use Test::More;
-use File::Temp qw(tempdir);
 use Socket qw(SOCK_STREAM IPPROTO_TCP SOL_SOCKET);
+use PublicInbox::TestCommon;
 # IO::Poll is part of the standard library, but distros may split them off...
-foreach my $mod (qw(IO::Socket::SSL IO::Poll)) {
-       eval "require $mod";
-       plan skip_all => "$mod missing for $0" if $@;
-}
+require_mods(qw(IO::Socket::SSL IO::Poll Plack::Util));
 my $cert = 'certs/server-cert.pem';
 my $key = 'certs/server-key.pem';
 unless (-r $key && -r $cert) {
@@ -18,19 +15,12 @@ unless (-r $key && -r $cert) {
 }
 use_ok 'PublicInbox::TLS';
 use_ok 'IO::Socket::SSL';
-require './t/common.perl';
 my $psgi = "./t/httpd-corner.psgi";
-my $tmpdir = tempdir('pi-httpd-https-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my ($tmpdir, $for_destroy) = tmpdir();
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
-my $httpd = 'blib/script/public-inbox-httpd';
 my $https = tcp_server();
-my ($pid, $tail_pid);
-END {
-       foreach ($pid, $tail_pid) {
-               kill 'TERM', $_ if defined $_;
-       }
-};
+my $td;
 my $https_addr = $https->sockhost . ':' . $https->sockport;
 
 for my $args (
@@ -39,15 +29,9 @@ for my $args (
        for ($out, $err) {
                open my $fh, '>', $_ or die "truncate: $!";
        }
-       if (my $tail_cmd = $ENV{TAIL}) { # don't assume GNU tail
-               $tail_pid = fork;
-               if (defined $tail_pid && $tail_pid == 0) {
-                       exec(split(' ', $tail_cmd), $out, $err);
-               }
-       }
-       my $cmd = [ $httpd, '-W0', @$args,
+       my $cmd = [ '-httpd', '-W0', @$args,
                        "--stdout=$out", "--stderr=$err", $psgi ];
-       $pid = spawn_listener(undef, $cmd, [ $https ]);
+       $td = start_script($cmd, undef, { 3 => $https });
        my %o = (
                SSL_hostname => 'server.local',
                SSL_verifycn_name => 'server.local',
@@ -103,7 +87,7 @@ for my $args (
 
        SKIP: {
                skip 'TCP_DEFER_ACCEPT is Linux-only', 2 if $^O ne 'linux';
-               my $var = Socket::TCP_DEFER_ACCEPT();
+               my $var = eval { Socket::TCP_DEFER_ACCEPT() } // 9;
                defined(my $x = getsockopt($https, IPPROTO_TCP, $var)) or die;
                ok(unpack('i', $x) > 0, 'TCP_DEFER_ACCEPT set on https');
        };
@@ -119,15 +103,9 @@ for my $args (
        };
 
        $c = undef;
-       kill('TERM', $pid);
-       is($pid, waitpid($pid, 0), 'httpd exited successfully');
+       $td->kill;
+       $td->join;
        is($?, 0, 'no error in exited process');
-       $pid = undef;
-       if (defined $tail_pid) {
-               kill 'TERM', $tail_pid;
-               waitpid($tail_pid, 0);
-               $tail_pid = undef;
-       }
 }
 done_testing();
 1;