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
28 "perl -I$FindBin::Bin/../lib $FindBin::Bin/../script/catalyst.pl TestApp";
\r
29 chdir "$FindBin::Bin/..";
\r
30 File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
\r
32 # remove TestApp's tests
\r
33 rmtree 't/tmp/TestApp/t';
\r
35 # spawn the standalone HTTP server
\r
36 my $port = 30000 + int rand( 1 + 10000 );
\r
37 my $pid = open my $server,
\r
38 "perl -I$FindBin::Bin/../lib $FindBin::Bin/../t/tmp/TestApp/script/testapp_server.pl -port $port -restart 2>&1 |"
\r
39 or die "Unable to spawn standalone HTTP server: $!";
\r
41 # wait for it to start
\r
42 print "Waiting for server to start...\n";
\r
43 while ( check_port( 'localhost', $port ) != 1 ) {
\r
47 # change various files
\r
49 "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp.pm",
\r
50 "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Action/Begin.pm",
\r
51 "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Engine/Request/URI.pm",
\r
54 # change some files and make sure the server restarts itself
\r
56 my $index = rand @files;
\r
57 open my $pm, '>>', $files[$index]
\r
58 or die "Unable to open $files[$index] for writing: $!";
\r
62 # give the server time to notice the change and restart
\r
65 while ( check_port( 'localhost', $port ) != 1 ) {
\r
67 # wait for it to restart
\r
69 die "Server appears to have died" if $count++ > 50;
\r
71 my $response = get("http://localhost:$port/action/default");
\r
72 like( $response, qr/Catalyst::Request/, 'Non-error restart, request OK' );
\r
74 #print $server->getline;
\r
77 # add errors to the file and make sure server does not die or restart
\r
79 my $index = rand @files;
\r
80 open my $pm, '>>', $files[$index]
\r
81 or die "Unable to open $files[$index] for writing: $!";
\r
85 # give the server time to notice the change
\r
87 if ( check_port( 'localhost', $port ) != 1 ) {
\r
88 die "Server appears to have died";
\r
90 my $response = get("http://localhost:$port/action/default");
\r
91 like( $response, qr/Catalyst::Request/,
\r
92 'Syntax error, no restart, request OK' );
\r
94 #print $server->getline;
\r
102 rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
\r
105 my ( $host, $port ) = @_;
\r
107 my $remote = IO::Socket::INET->new(
\r