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/var" if -d "$FindBin::Bin/../../t/var";
\r
24 # create a TestApp and copy the test libs into it
\r
25 mkdir "$FindBin::Bin/../../t/var";
\r
26 chdir "$FindBin::Bin/../../t/var";
\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/var/TestApp/lib' );
\r
31 # spawn the standalone HTTP server
\r
32 my $port = 30000 + int rand(1 + 10000);
\r
33 my $pid = open my $server,
\r
34 "perl -I$FindBin::Bin/../../lib $FindBin::Bin/../../t/var/TestApp/script/testapp_server.pl -port $port -restart 2>&1 |"
\r
35 or die "Unable to spawn standalone HTTP server: $!";
\r
37 # wait for it to start
\r
38 print "Waiting for server to start...\n";
\r
39 while ( check_port( 'localhost', $port ) != 1 ) {
\r
43 # change various files
\r
45 "$FindBin::Bin/../../t/var/TestApp/lib/TestApp.pm",
\r
46 "$FindBin::Bin/../../t/var/TestApp/lib/TestApp/Controller/Action/Begin.pm",
\r
47 "$FindBin::Bin/../../t/var/TestApp/lib/TestApp/Controller/Engine/Request/URI.pm",
\r
50 # change some files and make sure the server restarts itself
\r
52 my $index = rand @files;
\r
53 open my $pm, '>>', $files[$index]
\r
54 or die "Unable to open $files[$index] for writing: $!";
\r
58 # give the server time to notice the change and restart
\r
61 while ( check_port( 'localhost', $port ) != 1 ) {
\r
62 # wait for it to restart
\r
64 die "Server appears to have died" if $count++ > 50;
\r
66 my $response = get("http://localhost:$port/action/default");
\r
67 like( $response, qr/Catalyst::Request/, 'Request OK' );
\r
69 #print $server->getline;
\r
72 # add errors to the file and make sure server does not die or restart
\r
74 my $index = rand @files;
\r
75 open my $pm, '>>', $files[$index]
\r
76 or die "Unable to open $files[$index] for writing: $!";
\r
80 # give the server time to notice the change
\r
82 if ( check_port( 'localhost', $port ) != 1 ) {
\r
83 die "Server appears to have died";
\r
85 my $response = get("http://localhost:$port/action/default");
\r
86 like( $response, qr/Catalyst::Request/, 'Request OK' );
\r
88 #print $server->getline;
\r
96 rmtree "$FindBin::Bin/../../t/var" if -d "$FindBin::Bin/../../t/var";
\r
99 my ( $host, $port ) = @_;
\r
101 my $remote = IO::Socket::INET->new(
\r