@@ -25,9 +25,19 @@ SKIP: {
25
25
$command = qq' mcr $^X t/referer-server' ;
26
26
}
27
27
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
+
28
32
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
30
35
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
+ }
31
41
chomp $url ;
32
42
33
43
$agent -> get($url );
@@ -65,12 +75,22 @@ SKIP: {
65
75
is( $agent -> status, 200, ' Got fourth page' ) or diag $agent -> res-> message;
66
76
is( $agent -> content, " Referer: '$ref '" , ' Custom referer can be set' );
67
77
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
+
68
82
$agent -> get( $url . ' quit_server' );
69
83
ok( $agent -> success, ' Quit OK' );
70
84
}
71
85
72
86
memory_cycle_ok( $agent , ' No memory cycles found' );
73
87
74
88
END {
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
+ }
76
96
}
0 commit comments