DnsNameResolverTest.testTruncated0(...) should only close socket once envelope is received (#9469)
Motivation: We should only ever close the underlying tcp socket once we received the envelope to ensure we never race in the test. Modifications: - Only close socket once we received the envelope - Set REUSE_ADDR Result: More robust test
This commit is contained in:
parent
cdb92c5b0f
commit
a1742d95da
@ -2768,7 +2768,6 @@ public class DnsNameResolverTest {
|
||||
dnsServer2.start();
|
||||
DnsNameResolver resolver = null;
|
||||
ServerSocket serverSocket = null;
|
||||
Socket socket = null;
|
||||
try {
|
||||
DnsNameResolverBuilder builder = newResolver()
|
||||
.queryTimeoutMillis(10000)
|
||||
@ -2779,6 +2778,7 @@ public class DnsNameResolverTest {
|
||||
if (tcpFallback) {
|
||||
// If we are configured to use TCP as a fallback also bind a TCP socket
|
||||
serverSocket = new ServerSocket(dnsServer2.localAddress().getPort());
|
||||
serverSocket.setReuseAddress(true);
|
||||
|
||||
builder.socketChannelType(NioSocketChannel.class);
|
||||
}
|
||||
@ -2788,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 = serverSocket.accept();
|
||||
Socket socket = serverSocket.accept();
|
||||
|
||||
IoBuffer ioBuffer = IoBuffer.allocate(1024);
|
||||
new DnsMessageEncoder().encode(ioBuffer, messageRef.get());
|
||||
@ -2806,7 +2806,11 @@ public class DnsNameResolverTest {
|
||||
socket.getOutputStream().write(ioBuffer.get());
|
||||
}
|
||||
socket.getOutputStream().flush();
|
||||
socket.getOutputStream().close();
|
||||
// Let's wait until we received the envelope before closing the socket.
|
||||
envelopeFuture.syncUninterruptibly();
|
||||
|
||||
socket.close();
|
||||
serverSocket.close();
|
||||
}
|
||||
|
||||
AddressedEnvelope<DnsResponse, InetSocketAddress> envelope = envelopeFuture.syncUninterruptibly().getNow();
|
||||
@ -2831,12 +2835,6 @@ public class DnsNameResolverTest {
|
||||
envelope.release();
|
||||
} finally {
|
||||
dnsServer2.stop();
|
||||
if (socket != null) {
|
||||
socket.close();
|
||||
}
|
||||
if (serverSocket != null) {
|
||||
serverSocket.close();
|
||||
}
|
||||
if (resolver != null) {
|
||||
resolver.close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user