Skip to content

Commit

Permalink
try to find start_server from $PATH and $^X, or skip most tests (but …
Browse files Browse the repository at this point in the history
…not all) if not found
  • Loading branch information
kazuho committed Jan 6, 2010
1 parent 483960c commit 1a1209f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Makefile.PL
Expand Up @@ -7,6 +7,7 @@ requires 'Plack' => 0.9020;
requires 'Parallel::Prefork' => 0.05; # since Plack does not intentionally requires P::Prefork required by Standalone::Prefork requires 'Parallel::Prefork' => 0.05; # since Plack does not intentionally requires P::Prefork required by Standalone::Prefork


requires 'Server::Starter' => 0.05; requires 'Server::Starter' => 0.05;
test_requires 'Test::TCP' => 0.15; test_requires 'Test::More' => 0.88;
test_requires 'Test::TCP' => 0.15;


WriteAll; WriteAll;
51 changes: 30 additions & 21 deletions t/00base.t
@@ -1,34 +1,43 @@
use strict; use strict;
use warnings; use warnings;


use File::Basename ();
use LWP::Simple (); use LWP::Simple ();
use Test::TCP (); use Test::TCP ();


use Test::More tests => 2; use Test::More;


BEGIN { BEGIN {
use_ok('Server::Starter'); use_ok('Server::Starter');
}; };


my $port = Test::TCP::empty_port(); my ($start_server) = grep { -x $_ } map { "$_/start_server" } (

File::Basename::dirname($^X),
my $server_pid = fork(); split /:/, $ENV{PATH},
die "fork failed:$!" );
unless defined $server_pid;
if ($server_pid == 0) { if ($start_server) {
# child == server my $port = Test::TCP::empty_port();
exec( my $server_pid = fork();
"start_server", die "fork failed:$!"
"--port=$port", unless defined $server_pid;
qw(-- plackup -s Standalone::Prefork::Server::Starter t/00base-hello.psgi), if ($server_pid == 0) {
); # child == server
die "failed to launch server using start_server:$!"; exec(
$start_server,
"--port=$port",
qw(-- plackup -s Standalone::Prefork::Server::Starter t/00base-hello.psgi),
);
die "failed to launch server using start_server:$!";
}
sleep 1;

is(LWP::Simple::get("http://127.0.0.1:$port/"), 'hello');

kill 'TERM', $server_pid;
while (wait == -1) {}
} else {
warn "could not find `start_server' next to $^X nor from \$PATH, skipping tests";
} }


sleep 1; done_testing;

is(LWP::Simple::get("http://127.0.0.1:$port/"), 'hello');

kill 'TERM', $server_pid;

while (wait == -1) {}

0 comments on commit 1a1209f

Please sign in to comment.