From: Florian Ragwitz Date: Wed, 2 Mar 2011 12:27:37 +0000 (+0100) Subject: Don't use the server.pl script in the live tests X-Git-Tag: 5.89003~94 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=d93d402c16035129944e4948a00309a5cd78a1c7;hp=281521fc4f8e929e00196aac501429bb6eef02d6 Don't use the server.pl script in the live tests Instead, just spin up a server with Plack::Loader. The script classes are already tested separately, so we only need this test to make sure live tests work. This is intended to aid a subsequent refactoring. --- diff --git a/t/author/http-server.t b/t/author/http-server.t index 5f8a213..9754857 100644 --- a/t/author/http-server.t +++ b/t/author/http-server.t @@ -5,7 +5,6 @@ use Test::More tests => 1; use File::Path; use FindBin; -use IPC::Open3; use IO::Socket; use Catalyst::Devel 1.0; @@ -31,19 +30,29 @@ rmtree '../t/tmp/TestApp/t' or die; # spawn the standalone HTTP server my $port = 30000 + int rand(1 + 10000); -my @cmd = ($^X, "-I$FindBin::Bin/../../lib", - "$FindBin::Bin/../../t/tmp/TestApp/script/testapp_server.pl", '--port', $port ); -my $pid = open3( undef, my $server, undef, @cmd) - or die "Unable to spawn standalone HTTP server: $!"; - -# wait for it to start -print "Waiting for server to start...\n"; -my $timeout = 30; -my $count = 0; -while ( check_port( 'localhost', $port ) != 1 ) { - sleep 1; - die("Server did not start within $timeout seconds: " . join(' ', @cmd)) - if $count++ > $timeout; + +my $pid = fork; +if ($pid) { + # parent. + print "Waiting for server to start...\n"; + my $timeout = 30; + my $count = 0; + while ( check_port( 'localhost', $port ) != 1 ) { + sleep 1; + die "Server did not start within $timeout seconds:" + if $count++ > $timeout; + } +} elsif ($pid == 0) { + # child process + unshift @INC, "$tmpdir/TestApp/lib", "$FindBin::Bin/../../lib"; + require TestApp; + + my $psgi_app = TestApp->_wrapped_legacy_psgi_app(TestApp->psgi_app); + Plack::Loader->auto(port => $port)->run($psgi_app); + + exit 0; +} else { + die "fork failed: $!"; } # run the testsuite against the HTTP server @@ -61,7 +70,6 @@ else { # shut it down kill 'INT', $pid; -close $server; # clean up rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";