Skip to content

Commit

Permalink
now we retry 30 times (for total 30 sec) when the embedded TCP server…
Browse files Browse the repository at this point in the history
… fails to listen on the specified port.
  • Loading branch information
agentzh committed Sep 5, 2012
1 parent e2a7b2f commit 6798ca9
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions lib/Test/Nginx/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1328,14 +1328,36 @@ request:

#warn "Reply: ", $reply;

$tcp_socket = IO::Socket::INET->new(
LocalHost => '127.0.0.1',
LocalPort => $port,
Proto => 'tcp',
Reuse => 1,
Listen => 5,
Timeout => timeout(),
) or bail_out("$name - failed to create the tcp listening socket: $!");
my $err;
for (my $i = 0; $i < 30; $i++) {
$tcp_socket = IO::Socket::INET->new(
LocalHost => '127.0.0.1',
LocalPort => $port,
Proto => 'tcp',
Reuse => 1,
Listen => 5,
Timeout => timeout(),
);

if ($tcp_socket) {
last;
}

if ($!) {
$err = $!;
if ($err =~ /address already in use/i) {
warn "WARNING: failed to create the tcp listening socket: $err\n";
sleep 1;
next;
}
}

last;
}

if (!$tcp_socket && $err) {
bail_out("$name - failed to create the tcp listening socket: $err");
}

if (defined $block->tcp_query || defined $req_len) {
my $tb = Test::More->builder;
Expand Down

0 comments on commit 6798ca9

Please sign in to comment.