X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fhttpd.t;h=517329fbc5a37db2863479a6f46975c3c17a143a;hb=3c313f9034aac96182e2efdc2f92c40803626f32;hp=e0a2bf44164a0f79d6be8b6a34471337645352b0;hpb=3eb26fe04dae68612c841e749abd2848ce78ae59;p=public-inbox.git
diff --git a/t/httpd.t b/t/httpd.t
index e0a2bf44..517329fb 100644
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2018 all contributors
+# Copyright (C) 2016-2019 all contributors
# License: AGPL-3.0+
use strict;
use warnings;
@@ -8,13 +8,11 @@ foreach my $mod (qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status)) {
eval "require $mod";
plan skip_all => "$mod missing for httpd.t" if $@;
}
-use File::Temp qw/tempdir/;
-use IO::Socket::INET;
-use Socket qw(IPPROTO_TCP);
-require './t/common.perl';
+use Socket qw(IPPROTO_TCP SOL_SOCKET);
+use PublicInbox::TestCommon;
# FIXME: too much setup
-my $tmpdir = tempdir('pi-httpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my ($tmpdir, $for_destroy) = tmpdir();
my $home = "$tmpdir/pi-home";
my $err = "$tmpdir/stderr.log";
my $out = "$tmpdir/stdout.log";
@@ -22,18 +20,15 @@ my $maindir = "$tmpdir/main.git";
my $group = 'test-httpd';
my $addr = $group . '@example.com';
my $cfgpfx = "publicinbox.$group";
-my $httpd = 'blib/script/public-inbox-httpd';
-my $init = 'blib/script/public-inbox-init';
my $sock = tcp_server();
-my $pid;
+my $td;
use_ok 'PublicInbox::Git';
use_ok 'PublicInbox::Import';
use_ok 'Email::MIME';
-END { kill 'TERM', $pid if defined $pid };
{
local $ENV{HOME} = $home;
- ok(!system($init, $group, $maindir, 'http://example.com/', $addr),
- 'init ran properly');
+ my $cmd = [ '-init', $group, $maindir, 'http://example.com/', $addr ];
+ ok(run_script($cmd), 'init ran properly');
# ensure successful message delivery
{
@@ -54,14 +49,11 @@ EOF
$im->done($mime);
}
ok($sock, 'sock created');
- my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err" ];
- $pid = spawn_listener(undef, $cmd, [$sock]);
+ $cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err" ];
+ $td = start_script($cmd, undef, { 3 => $sock });
my $host = $sock->sockhost;
my $port = $sock->sockport;
- my $conn = IO::Socket::INET->new(PeerAddr => $host,
- PeerPort => $port,
- Proto => 'tcp',
- Type => SOCK_STREAM);
+ my $conn = tcp_connect($sock);
ok($conn, 'connected');
ok($conn->write("GET / HTTP/1.0\r\n\r\n"), 'wrote data to socket');
{
@@ -83,9 +75,8 @@ EOF
"http://$host:$port/$group", "$tmpdir/dumb.git"),
0, 'clone successful');
- ok(kill('TERM', $pid), 'killed httpd');
- $pid = undef;
- waitpid(-1, 0);
+ ok($td->kill, 'killed httpd');
+ $td->join;
is(system('git', "--git-dir=$tmpdir/clone.git",
qw(fsck --no-verbose)), 0,