Fix flaky test `AdminClientTest.testDefaultApiTimeoutOverride`
There is a race condition with the backoff sleep in the test case and setting the next allowed send time in the AdminClient. To fix it, we allow the test case to do the backoff sleep multiple times if needed.
Reviewers: Rajini Sivaram
@@ -2740,11 +2740,14 @@ public class KafkaAdminClientTest {
// Wait for the request to be timed out before backing off
TestUtils.waitForCondition(() -> !env.kafkaClient().hasInFlightRequests(),
"Timed out waiting for inFlightRequests to be timed out");
- time.sleep(retryBackoffMs);
// Since api timeout bound is not hit, AdminClient should retry
- TestUtils.waitForCondition(() -> env.kafkaClient().hasInFlightRequests(),
- "Timed out waiting for Metadata request to be sent");
+ TestUtils.waitForCondition(() -> {
+ boolean hasInflightRequests = env.kafkaClient().hasInFlightRequests();
+ if (!hasInflightRequests)
+ time.sleep(retryBackoffMs);
+ return hasInflightRequests;
+ }, "Timed out waiting for Metadata request to be sent");
time.sleep(requestTimeoutMs + 1);
TestUtils.assertFutureThrows(result.future, TimeoutException.class);
