Commit | Line | Data |
040850b3 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
040850b3 |
6 | use File::Path; |
7 | use FindBin; |
896c9ed2 |
8 | use IO::Socket; |
f0ee1a76 |
9 | use Test::More; |
10 | eval "use File::Copy::Recursive"; |
11 | |
f0ee1a76 |
12 | plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP}; |
ac93c094 |
13 | plan skip_all => 'File::Copy::Recursive required' if $@; |
55ddccae |
14 | plan tests => 1; |
040850b3 |
15 | |
16 | # clean up |
17 | rmtree "$FindBin::Bin/../../t/var" if -d "$FindBin::Bin/../../t/var"; |
18 | |
19 | # create a TestApp and copy the test libs into it |
20 | mkdir "$FindBin::Bin/../../t/var"; |
21 | chdir "$FindBin::Bin/../../t/var"; |
32e231eb |
22 | system "perl -I$FindBin::Bin/../../lib $FindBin::Bin/../../script/catalyst.pl TestApp"; |
040850b3 |
23 | chdir "$FindBin::Bin/../.."; |
24 | File::Copy::Recursive::dircopy( 't/live/lib', 't/var/TestApp/lib' ); |
25 | |
26 | # spawn the standalone HTTP server |
896c9ed2 |
27 | my $port = 30000 + int rand(1 + 10000); |
28 | my $pid = open my $server, |
e1b364f4 |
29 | "perl -I$FindBin::Bin/../../lib $FindBin::Bin/../../t/var/TestApp/script/testapp_server.pl -port $port 2>&1 |" |
040850b3 |
30 | or die "Unable to spawn standalone HTTP server: $!"; |
896c9ed2 |
31 | |
040850b3 |
32 | # wait for it to start |
896c9ed2 |
33 | print "Waiting for server to start...\n"; |
34 | while ( check_port( 'localhost', $port ) != 1 ) { |
35 | sleep 1; |
36 | } |
32e231eb |
37 | |
040850b3 |
38 | # run the testsuite against the HTTP server |
896c9ed2 |
39 | $ENV{CATALYST_SERVER} = "http://localhost:$port"; |
55ddccae |
40 | system( 'prove -r -Ilib/ t/live/' ); |
040850b3 |
41 | |
42 | # shut it down |
e1b364f4 |
43 | kill 'INT', $pid; |
896c9ed2 |
44 | close $server; |
040850b3 |
45 | |
46 | # clean up |
47 | rmtree "$FindBin::Bin/../../t/var" if -d "$FindBin::Bin/../../t/var"; |
896c9ed2 |
48 | |
55ddccae |
49 | ok( 'done' ); |
50 | |
896c9ed2 |
51 | sub check_port { |
52 | my ( $host, $port ) = @_; |
53 | |
54 | my $remote = IO::Socket::INET->new( |
55 | Proto => "tcp", |
56 | PeerAddr => $host, |
57 | PeerPort => $port |
58 | ); |
59 | if ($remote) { |
60 | close $remote; |
61 | return 1; |
62 | } |
63 | else { |
64 | return 0; |
65 | } |
66 | } |