Skip to content

Commit

Permalink
test: better test port availablility by binding
Browse files Browse the repository at this point in the history
Port connection test may return true while port was recently used on linux but not fully released.
Binding on port is definitively more reliable as more on the purpose.
  • Loading branch information
g-bougard committed Sep 28, 2018
1 parent c804161 commit 5531e90
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions t/lib/FusionInventory/Test/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ sub test_port {
my $paddr = sockaddr_in($port, $iaddr);
my $proto = getprotobyname('tcp');
if (socket(my $socket, PF_INET, SOCK_STREAM, $proto)) {
if (connect($socket, $paddr)) {
if (bind($socket, $paddr)) {
close $socket;
return 0;
return 1;
}
}

return 1;
return 0;
}

sub test_localhost {
Expand Down

0 comments on commit 5531e90

Please sign in to comment.