3 # This test tests the standalone server's auto-restart feature.
\r
13 use Time::HiRes qw/sleep/;
\r
14 eval "use Catalyst::Devel 1.0;";
\r
16 plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP};
\r
17 plan skip_all => 'Catalyst::Devel required' if $@;
\r
18 eval "use File::Copy::Recursive";
\r
19 plan skip_all => 'File::Copy::Recursive required' if $@;
\r
24 rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
\r
26 # create a TestApp and copy the test libs into it
\r
27 mkdir "$FindBin::Bin/../t/tmp";
\r
28 chdir "$FindBin::Bin/../t/tmp";
\r
30 "perl -I$FindBin::Bin/../lib $FindBin::Bin/../script/catalyst.pl TestApp";
\r
31 chdir "$FindBin::Bin/..";
\r
32 File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
\r
34 # remove TestApp's tests
\r
35 rmtree 't/tmp/TestApp/t';
\r
37 # spawn the standalone HTTP server
\r
38 my $port = 30000 + int rand( 1 + 10000 );
\r
39 my $pid = open my $server,
\r
40 "perl -I$FindBin::Bin/../lib $FindBin::Bin/../t/tmp/TestApp/script/testapp_server.pl -port $port -restart 2>&1 |"
\r
41 or die "Unable to spawn standalone HTTP server: $!";
\r
43 # wait for it to start
\r
44 print "Waiting for server to start...\n";
\r
45 while ( check_port( 'localhost', $port ) != 1 ) {
\r
49 # change various files
\r
51 "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp.pm",
\r
52 "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Action/Begin.pm",
\r
53 "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Engine/Request/URI.pm",
\r
56 # change some files and make sure the server restarts itself
\r
58 my $index = rand @files;
\r
59 open my $pm, '>>', $files[$index]
\r
60 or die "Unable to open $files[$index] for writing: $!";
\r
64 # give the server time to notice the change and restart
\r
67 while ( check_port( 'localhost', $port ) != 1 ) {
\r
69 # wait for it to restart
\r
71 die "Server appears to have died" if $count++ > 50;
\r
73 my $response = get("http://localhost:$port/action/default");
\r
74 like( $response, qr/Catalyst::Request/, 'Non-error restart, request OK' );
\r
76 #print $server->getline;
\r
79 # add errors to the file and make sure server does not die or restart
\r
81 my $index = rand @files;
\r
82 open my $pm, '>>', $files[$index]
\r
83 or die "Unable to open $files[$index] for writing: $!";
\r
87 # give the server time to notice the change
\r
89 if ( check_port( 'localhost', $port ) != 1 ) {
\r
90 die "Server appears to have died";
\r
92 my $response = get("http://localhost:$port/action/default");
\r
93 like( $response, qr/Catalyst::Request/,
\r
94 'Syntax error, no restart, request OK' );
\r
96 #print $server->getline;
\r
104 rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
\r
107 my ( $host, $port ) = @_;
\r
109 my $remote = IO::Socket::INET->new(
\r