X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fgit-http-backend.t;h=1d9bb9f3230b0d70a3568c54f488e047e95c7599;hb=9bd675d33ad1e49bd2ebe12a1d216216e61380de;hp=cb5e5d2555ac92a00fbda174be39fe627b016165;hpb=3d41aa23f35501ca92aab8aa42980fa73f7fa74f;p=public-inbox.git diff --git a/t/git-http-backend.t b/t/git-http-backend.t index cb5e5d25..1d9bb9f3 100644 --- a/t/git-http-backend.t +++ b/t/git-http-backend.t @@ -1,36 +1,29 @@ -# Copyright (C) 2016-2018 all contributors +# Copyright (C) 2016-2019 all contributors # License: AGPL-3.0+ +# +# Ensure buffering behavior in -httpd doesn't cause runaway memory use +# or data corruption use strict; use warnings; use Test::More; use File::Temp qw/tempdir/; -use IO::Socket; -use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD); -use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY); -use POSIX qw(dup2 setsid); -use Cwd qw(getcwd); +use POSIX qw(setsid); my $git_dir = $ENV{GIANT_GIT_DIR}; plan 'skip_all' => 'GIANT_GIT_DIR not defined' unless $git_dir; -foreach my $mod (qw(Danga::Socket BSD::Resource +foreach my $mod (qw(BSD::Resource Plack::Util Plack::Builder HTTP::Date HTTP::Status Net::HTTP)) { eval "require $mod"; plan skip_all => "$mod missing for git-http-backend.t" if $@; } -my $psgi = getcwd()."/t/git-http-backend.psgi"; +require './t/common.perl'; +my $psgi = "./t/git-http-backend.psgi"; my $tmpdir = tempdir('pi-git-http-backend-XXXXXX', TMPDIR => 1, CLEANUP => 1); 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; @@ -51,17 +44,9 @@ my $get_maxrss = sub { { ok($sock, 'sock created'); - $pid = fork; - if ($pid == 0) { # pretend to be systemd - fcntl($sock, F_SETFD, 0); - dup2(fileno($sock), 3) or die "dup2 failed: $!\n"; - $ENV{LISTEN_PID} = $$; - $ENV{LISTEN_FDS} = 1; - $ENV{TEST_CHUNK} = '1'; - exec $httpd, "--stdout=$out", "--stderr=$err", $psgi; - die "FAIL: $!\n"; - } - ok(defined $pid, 'forked httpd process successfully'); + my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err", $psgi ]; + ok(defined($pid = spawn_listener(undef, $cmd, [$sock])), + 'forked httpd process successfully'); } my $mem_a = $get_maxrss->(); @@ -87,6 +72,8 @@ SKIP: { my ($code, $mess, %h) = $http->read_response_headers; is(200, $code, 'got 200 success for pack'); is($max, $h{'Content-Length'}, 'got expected Content-Length for pack'); + + # no $http->read_entity_body, here, since we want to force buffering foreach my $i (1..3) { sleep 1; my $diff = $get_maxrss->() - $mem_a;