@@ -25,9 +25,19 @@ SKIP: {
2525 $command = qq' mcr $^X t/referer-server' ;
2626 }
2727
28+ # Set a timeout to ensure we don't hang forever
29+ local $SIG {ALRM } = sub { die " Timeout waiting for test server to start\n " };
30+ alarm 10; # 10 second timeout
31+
2832 open $server , " $command |" or die " Couldn't spawn fake server: $! " ;
29- sleep 1; # give the child some time
33+
34+ # Wait for server startup with proper error handling
3035 my $url = <$server >;
36+ alarm 0; # Cancel the alarm
37+
38+ if (!defined $url || $url eq ' ' ) {
39+ die " Failed to get a response from test server\n " ;
40+ }
3141 chomp $url ;
3242
3343 $agent -> get($url );
@@ -65,12 +75,22 @@ SKIP: {
6575 is( $agent -> status, 200, ' Got fourth page' ) or diag $agent -> res-> message;
6676 is( $agent -> content, " Referer: '$ref '" , ' Custom referer can be set' );
6777
78+ # Add a timeout for the server shutdown
79+ local $SIG {ALRM } = sub { die " Timeout waiting for server to quit\n " };
80+ alarm 5; # 5 second timeout
81+
6882 $agent -> get( $url . ' quit_server' );
6983 ok( $agent -> success, ' Quit OK' );
7084}
7185
7286memory_cycle_ok( $agent , ' No memory cycles found' );
7387
7488END {
75- close $server if $server ;
89+ if ($server ) {
90+ # Make sure we don't hang in END block
91+ local $SIG {ALRM } = sub { warn " Timeout closing server handle\n " ; exit 1 };
92+ alarm 3;
93+ close $server ;
94+ alarm 0;
95+ }
7696}
0 commit comments