@@ -25,9 +25,20 @@ 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 }
30+ = sub { die " Timeout waiting for test server to start\n " };
31+ alarm 10; # 10 second timeout
32+
2833 open $server , " $command |" or die " Couldn't spawn fake server: $! " ;
29- sleep 1; # give the child some time
34+
35+ # Wait for server startup with proper error handling
3036 my $url = <$server >;
37+ alarm 0; # Cancel the alarm
38+
39+ if ( !defined $url || $url eq ' ' ) {
40+ die " Failed to get a response from test server\n " ;
41+ }
3142 chomp $url ;
3243
3344 $agent -> get($url );
@@ -65,12 +76,24 @@ SKIP: {
6576 is( $agent -> status, 200, ' Got fourth page' ) or diag $agent -> res-> message;
6677 is( $agent -> content, " Referer: '$ref '" , ' Custom referer can be set' );
6778
79+ # Add a timeout for the server shutdown
80+ local $SIG {ALRM } = sub { die " Timeout waiting for server to quit\n " };
81+ alarm 5; # 5 second timeout
82+
6883 $agent -> get( $url . ' quit_server' );
6984 ok( $agent -> success, ' Quit OK' );
7085}
7186
7287memory_cycle_ok( $agent , ' No memory cycles found' );
7388
7489END {
75- close $server if $server ;
90+ if ($server ) {
91+
92+ # Make sure we don't hang in END block
93+ local $SIG {ALRM }
94+ = sub { warn " Timeout closing server handle\n " ; exit 1 };
95+ alarm 3;
96+ close $server ;
97+ alarm 0;
98+ }
7699}
0 commit comments