MINOR: Add Timed wait to SslTransportLayerTest.testNetworkThreadTimeRecorded
Avoid test hanging when there is a failure by limiting wait time.
@@ -645,7 +645,7 @@ public class SslTransportLayerTest {
String message = TestUtils.randomString(1024 * 1024);
NetworkTestUtils.waitForChannelReady(selector, node);
- KafkaChannel channel = selector.channel(node);
+ final KafkaChannel channel = selector.channel(node);
assertTrue("SSL handshake time not recorded", channel.getAndResetNetworkThreadTimeNanos() > 0);
assertEquals("Time not reset", 0, channel.getAndResetNetworkThreadTimeNanos());
@@ -661,10 +661,20 @@ public class SslTransportLayerTest {
assertEquals(0, selector.completedReceives().size());
selector.unmute(node);
- while (selector.completedReceives().isEmpty()) {
+ // Wait for echo server to send the message back
+ TestUtils.waitForCondition(new TestCondition() {
+ @Override
+ public boolean conditionMet() {
+ try {
selector.poll(100L);
assertEquals(0, selector.numStagedReceives(channel));
+ } catch (IOException e) {
+ return false;
}
+ return !selector.completedReceives().isEmpty();
+ }
+ }, "Timed out waiting for a message to receive from echo server");
+
long receiveTimeNanos = channel.getAndResetNetworkThreadTimeNanos();
assertTrue("Receive time not recorded: " + receiveTimeNanos, receiveTimeNanos > 0);
}
