Skip to content

Try harder not to hang in referrer.t #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions t/local/referer.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ SKIP: {
$command = qq'mcr $^X t/referer-server';
}

# Set a timeout to ensure we don't hang forever
local $SIG{ALRM}
= sub { die "Timeout waiting for test server to start\n" };
alarm 10; # 10 second timeout

open $server, "$command |" or die "Couldn't spawn fake server: $!";
sleep 1; # give the child some time

# Wait for server startup with proper error handling
my $url = <$server>;
alarm 0; # Cancel the alarm

if ( !defined $url || $url eq '' ) {
die "Failed to get a response from test server\n";
}
chomp $url;

$agent->get($url);
Expand Down Expand Up @@ -65,12 +76,24 @@ SKIP: {
is( $agent->status, 200, 'Got fourth page' ) or diag $agent->res->message;
is( $agent->content, "Referer: '$ref'", 'Custom referer can be set' );

# Add a timeout for the server shutdown
local $SIG{ALRM} = sub { die "Timeout waiting for server to quit\n" };
alarm 5; # 5 second timeout

$agent->get( $url . 'quit_server' );
ok( $agent->success, 'Quit OK' );
}

memory_cycle_ok( $agent, 'No memory cycles found' );

END {
close $server if $server;
if ($server) {

# Make sure we don't hang in END block
local $SIG{ALRM}
= sub { warn "Timeout closing server handle\n"; exit 1 };
alarm 3;
close $server;
alarm 0;
}
}