about summary refs log tree commit
path: root/t/httpd.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-11-24 00:22:31 +0000
committerEric Wong <e@80x24.org>2019-11-24 21:46:49 +0000
commite05912ae3899a0f50a6baf3b6c1892789d24f6b1 (patch)
tree3b031d7478b78b77ae66eaa57360e21f2286f6c1 /t/httpd.t
parent8576a48b2344905229737fde45498c80a1171ca5 (diff)
downloadpublic-inbox-e05912ae3899a0f50a6baf3b6c1892789d24f6b1.tar.gz
We can shave several hundred milliseconds off tests which spawn
daemons by preloading and avoiding startup time for common
modules which are already loaded in the parent process.

This also gives ENV{TAIL} support to all tests which support
daemons which log to stdout/stderr.
Diffstat (limited to 't/httpd.t')
-rw-r--r--t/httpd.t13
1 files changed, 5 insertions, 8 deletions
diff --git a/t/httpd.t b/t/httpd.t
index e7527ed6..ce8063b2 100644
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -21,13 +21,11 @@ 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 $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;
         my $cmd = [ '-init', $group, $maindir, 'http://example.com/', $addr ];
@@ -52,8 +50,8 @@ EOF
                 $im->done($mime);
         }
         ok($sock, 'sock created');
-        $cmd = [ $httpd, '-W0', "--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 = tcp_connect($sock);
@@ -78,9 +76,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,