3 # This test tests the standalone server's auto-restart feature.
\r
13 use Time::HiRes qw/sleep/;
\r
14 eval "use File::Copy::Recursive";
\r
16 plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP};
\r
17 plan skip_all => 'File::Copy::Recursive required' if $@;
\r
22 rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
\r
24 # create a TestApp and copy the test libs into it
\r
25 mkdir "$FindBin::Bin/../../t/tmp";
\r
26 chdir "$FindBin::Bin/../../t/tmp";
\r
27 system "perl -I$FindBin::Bin/../../lib $FindBin::Bin/../../script/catalyst.pl TestApp";
\r
28 chdir "$FindBin::Bin/../..";
\r
29 File::Copy::Recursive::dircopy( 't/live/lib', 't/tmp/TestApp/lib' );
\r
31 # remove TestApp's tests
\r
32 rmtree 't/tmp/TestApp/t';
\r
34 # spawn the standalone HTTP server
\r
35 my $port = 30000 + int rand(1 + 10000);
\r
36 my $pid = open my $server,
\r
37 "perl -I$FindBin::Bin/../../lib $FindBin::Bin/../../t/tmp/TestApp/script/testapp_server.pl -port $port -restart 2>&1 |"
\r
38 or die "Unable to spawn standalone HTTP server: $!";
\r
40 # wait for it to start
\r
41 print "Waiting for server to start...\n";
\r
42 while ( check_port( 'localhost', $port ) != 1 ) {
\r
46 # change various files
\r
48 "$FindBin::Bin/../../t/tmp/TestApp/lib/TestApp.pm",
\r
49 "$FindBin::Bin/../../t/tmp/TestApp/lib/TestApp/Controller/Action/Begin.pm",
\r
50 "$FindBin::Bin/../../t/tmp/TestApp/lib/TestApp/Controller/Engine/Request/URI.pm",
\r
53 # change some files and make sure the server restarts itself
\r
55 my $index = rand @files;
\r
56 open my $pm, '>>', $files[$index]
\r
57 or die "Unable to open $files[$index] for writing: $!";
\r
61 # give the server time to notice the change and restart
\r
64 while ( check_port( 'localhost', $port ) != 1 ) {
\r
65 # wait for it to restart
\r
67 die "Server appears to have died" if $count++ > 50;
\r
69 my $response = get("http://localhost:$port/action/default");
\r
70 like( $response, qr/Catalyst::Request/, 'Non-error restart, request OK' );
\r
72 #print $server->getline;
\r
75 # add errors to the file and make sure server does not die or restart
\r
77 my $index = rand @files;
\r
78 open my $pm, '>>', $files[$index]
\r
79 or die "Unable to open $files[$index] for writing: $!";
\r
83 # give the server time to notice the change
\r
85 if ( check_port( 'localhost', $port ) != 1 ) {
\r
86 die "Server appears to have died";
\r
88 my $response = get("http://localhost:$port/action/default");
\r
89 like( $response, qr/Catalyst::Request/, 'Syntax error, no restart, request OK' );
\r
91 #print $server->getline;
\r
99 rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
\r
102 my ( $host, $port ) = @_;
\r
104 my $remote = IO::Socket::INET->new(
\r