Fix flaky DnsNameResolverTest.testTruncatedWithTcpFallback (#9262)

Motivation:

testTruncatedWithTcpFallback was flacky as we may end up closing the socket before we could read all data. We should only close the socket after we succesfully read all data.

Modifications:

Move socket.close() to finally block

Result:

Fix flaky test and so make the CI more stable again.
This commit is contained in:
Norman Maurer 2019-06-21 09:28:51 +02:00
parent ea2e4a7b3d
commit 780536ba72

View File

@ -2768,6 +2768,7 @@ public class DnsNameResolverTest {
dnsServer2.start();
DnsNameResolver resolver = null;
ServerSocket serverSocket = null;
Socket socket = null;
try {
DnsNameResolverBuilder builder = newResolver()
.queryTimeoutMillis(10000)
@ -2787,7 +2788,7 @@ public class DnsNameResolverTest {
if (tcpFallback) {
// If we are configured to use TCP as a fallback lets replay the dns message over TCP
Socket socket = serverSocket.accept();
socket = serverSocket.accept();
IoBuffer ioBuffer = IoBuffer.allocate(1024);
new DnsMessageEncoder().encode(ioBuffer, messageRef.get());
@ -2806,7 +2807,6 @@ public class DnsNameResolverTest {
}
socket.getOutputStream().flush();
socket.getOutputStream().close();
socket.close();
}
AddressedEnvelope<DnsResponse, InetSocketAddress> envelope = envelopeFuture.syncUninterruptibly().getNow();
@ -2831,6 +2831,9 @@ public class DnsNameResolverTest {
envelope.release();
} finally {
dnsServer2.stop();
if (socket != null) {
socket.close();
}
if (serverSocket != null) {
serverSocket.close();
}