chia7712 commented on code in PR #18145:
URL: https://github.com/apache/kafka/pull/18145#discussion_r1881098340
##########
test-common/src/main/java/org/apache/kafka/common/test/TestUtils.java:
##########
@@ -117,40 +116,26 @@ public static void waitForCondition(final
Supplier<Boolean> testCondition, final
*/
public static void waitForCondition(final Supplier<Boolean> testCondition,
final long maxWaitMs,
- String conditionDetails
- ) throws InterruptedException {
- retryOnExceptionWithTimeout(() -> {
- String conditionDetail = conditionDetails == null ? "" :
conditionDetails;
- if (!testCondition.get())
- throw new TimeoutException("Condition not met within timeout "
+ maxWaitMs + ". " + conditionDetail);
- });
- }
-
- /**
- * Wait for the given runnable to complete successfully, i.e. throw now
{@link Exception}s or
- * {@link AssertionError}s, or for the given timeout to expire. If the
timeout expires then the
- * last exception or assertion failure will be thrown thus providing
context for the failure.
- *
- * @param runnable the code to attempt to execute successfully.
- * @throws InterruptedException if the current thread is interrupted while
waiting for {@code runnable} to complete successfully.
- */
- static void retryOnExceptionWithTimeout(final Runnable runnable) throws
InterruptedException {
- final long expectedEnd = System.currentTimeMillis() +
DEFAULT_TIMEOUT_MS;
+ String conditionDetails) throws
InterruptedException {
+ final long expectedEnd = System.currentTimeMillis() + maxWaitMs;
while (true) {
try {
- runnable.run();
- return;
+ String conditionDetail = conditionDetails == null ? "" :
conditionDetails;
+ if (testCondition.get()) {
Review Comment:
Could you please do this check before creating `conditionDetail`?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]