Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
import java.security.Security;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import javax.net.ssl.HandshakeCompletedEvent;
Expand Down Expand Up @@ -538,6 +540,7 @@ public void testClientRenegotiationFails() throws Throwable {
SSLSocket clientSocket = null;
SSLSocket serverSocket = null;
final AtomicInteger handshakesCompleted = new AtomicInteger(0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can remove handshakesCompleted after adding the count down.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it.

The comment below states that we want to check that the handshake completes only once and not twice.

Now, the check is performed in the finally block, and the game should be over at that point.

This change slows down the test by forcing a synchronization point.

As we are waiting only for the first call we could still have a race and miss the second call but at least we are not changing the core logic of this test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I would like to keep the AtomicInteger

final CountDownLatch handshakeCompleted = new CountDownLatch(1);
try {
InetSocketAddress localServerAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), port);
listeningSocket.bind(localServerAddress);
Expand All @@ -550,6 +553,7 @@ public SSLSocket call() throws Exception {
@Override
public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) {
handshakesCompleted.getAndIncrement();
handshakeCompleted.countDown();
}
});
assertEquals(1, sslSocket.getInputStream().read());
Expand Down Expand Up @@ -582,6 +586,7 @@ public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent)
workerPool.shutdown();
// Make sure the first handshake completed and only the second
// one failed.
handshakeCompleted.await(5, TimeUnit.SECONDS);
assertEquals(1, handshakesCompleted.get());
}
}
Expand Down