]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/git-http-backend.t
tests: use File::Temp->newdir instead of tempdir()
[public-inbox.git] / t / git-http-backend.t
index fc2d5462db345ee9638f59833b38b7737c5dd4c8..a927d89ee272b63a22b4eb937e67479b58d0694e 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Ensure buffering behavior in -httpd doesn't cause runaway memory use
@@ -6,9 +6,8 @@
 use strict;
 use warnings;
 use Test::More;
-use File::Temp qw/tempdir/;
-use IO::Socket::INET;
 use POSIX qw(setsid);
+require './t/common.perl';
 
 my $git_dir = $ENV{GIANT_GIT_DIR};
 plan 'skip_all' => 'GIANT_GIT_DIR not defined' unless $git_dir;
@@ -18,24 +17,14 @@ foreach my $mod (qw(BSD::Resource
        eval "require $mod";
        plan skip_all => "$mod missing for git-http-backend.t" if $@;
 }
-require './t/common.perl';
 my $psgi = "./t/git-http-backend.psgi";
-my $tmpdir = tempdir('pi-git-http-backend-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 %opts = (
-       LocalAddr => '127.0.0.1',
-       ReuseAddr => 1,
-       Proto => 'tcp',
-       Type => SOCK_STREAM,
-       Listen => 1024,
-);
-my $sock = IO::Socket::INET->new(%opts);
+my $sock = tcp_server();
 my $host = $sock->sockhost;
 my $port = $sock->sockport;
-my $pid;
-END { kill 'TERM', $pid if defined $pid };
+my $td;
 
 my $get_maxrss = sub {
         my $http = Net::HTTP->new(Host => "$host:$port");
@@ -52,9 +41,8 @@ my $get_maxrss = sub {
 
 {
        ok($sock, 'sock created');
-       my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err", $psgi ];
-       ok(defined($pid = spawn_listener(undef, $cmd, [$sock])),
-          'forked httpd process successfully');
+       my $cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err", $psgi ];
+       $td = start_script($cmd, undef, { 3 => $sock });
 }
 my $mem_a = $get_maxrss->();
 
@@ -121,9 +109,8 @@ SKIP: {
 }
 
 {
-       ok(kill('TERM', $pid), 'killed httpd');
-       $pid = undef;
-       waitpid(-1, 0);
+       ok($td->kill, 'killed httpd');
+       $td->join;
 }
 
 done_testing();