d8tltanc commented on a change in pull request #8683: URL: https://github.com/apache/kafka/pull/8683#discussion_r443903361
########## File path: clients/src/test/java/org/apache/kafka/clients/ClusterConnectionStatesTest.java ########## @@ -321,4 +325,37 @@ public void testIsPreparingConnection() { connectionStates.disconnected(nodeId1, time.milliseconds()); assertFalse(connectionStates.isPreparingConnection(nodeId1)); } + + @Test + public void testExponentialConnectionSetupTimeout() { + assertTrue(connectionStates.canConnect(nodeId1, time.milliseconds())); + + // Check the exponential timeout growth + for (int n = 0; n <= Math.log((double) connectionSetupTimeoutMaxMs / connectionSetupTimeoutMs) / Math.log(2); n++) { + connectionStates.connecting(nodeId1, time.milliseconds(), "localhost", ClientDnsLookup.DEFAULT); + assertTrue(connectionStates.connectingNodes().contains(nodeId1)); + assertEquals(connectionSetupTimeoutMs * Math.pow(2, n), + connectionStates.connectionSetupTimeoutMs(nodeId1), + connectionSetupTimeoutMs * Math.pow(2, n) * 0.2); + connectionStates.disconnected(nodeId1, time.milliseconds()); + assertFalse(connectionStates.connectingNodes().contains(nodeId1)); + } + + // Check the timeout value upper bound + connectionStates.connecting(nodeId1, time.milliseconds(), "localhost", ClientDnsLookup.DEFAULT); + assertEquals(connectionStates.connectionSetupTimeoutMs(nodeId1), connectionSetupTimeoutMaxMs, connectionSetupTimeoutMaxMs * 0.2); Review comment: Good catch. The `expected` should be what you suggested. Refactored. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org