[lldb] [unittest] Avoid mixing '127.0.0.1' and 'localhost'

Fix the tests not to use '127.0.0.1' and 'localhost' interchangeably.
More specifically, since tests bind specifically to 127.0.0.1, connect
to that address as well; using 'localhost' can resolve to IPv6 address
which can cause issues -- for example, if the matching port happens to
be used by some other process, the tests hang forever waiting for
the client to connect.

While technically the case of randomly selected IPv4 port being taken
on IPv6 loopback is not very likely, NetBSD happens to be suffering from
some weird kernel issue where connection to that port succeeds
nevertheless.  Until we can really figure out what goes wrong there,
this saves us from the tests hanging randomly.

Differential Revision: https://reviews.llvm.org/D58131

llvm-svn: 353868
This commit is contained in:
Michal Gorny 2019-02-12 18:09:00 +00:00
parent 34bead750c
commit f6e5594e81
2 changed files with 3 additions and 3 deletions

View File

@ -179,7 +179,7 @@ TEST_F(SocketTest, TCPListen0ConnectAccept) {
[=](const TCPSocket &s) {
char connect_remote_address[64];
snprintf(connect_remote_address, sizeof(connect_remote_address),
"localhost:%u", s.GetLocalPortNumber());
"127.0.0.1:%u", s.GetLocalPortNumber());
return std::string(connect_remote_address);
},
&socket_a_up, &socket_b_up);
@ -193,7 +193,7 @@ TEST_F(SocketTest, TCPGetAddress) {
[=](const TCPSocket &s) {
char connect_remote_address[64];
snprintf(connect_remote_address, sizeof(connect_remote_address),
"localhost:%u", s.GetLocalPortNumber());
"127.0.0.1:%u", s.GetLocalPortNumber());
return std::string(connect_remote_address);
},
&socket_a_up, &socket_b_up);

View File

@ -80,7 +80,7 @@ Expected<std::unique_ptr<TestClient>> TestClient::launchCustom(StringRef Log, Ar
return status.ToError();
args.AppendArgument(
("localhost:" + Twine(listen_socket.GetLocalPortNumber())).str());
("127.0.0.1:" + Twine(listen_socket.GetLocalPortNumber())).str());
for (StringRef arg : ServerArgs)
args.AppendArgument(arg);