voonhous commented on code in PR #17677:
URL: https://github.com/apache/hudi/pull/17677#discussion_r2643414768
##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/utils/TestUtils.java:
##########
@@ -157,4 +159,14 @@ public static String
amendCompletionTimeToLatest(HoodieTableMetaClient metaClien
Files.move(sourcePath, newFilePath);
return newCompletionTime;
}
+
+ public static boolean waitUntil(BooleanSupplier condition, int
timeoutSeconds) throws InterruptedException {
+ for (int i = 0; i < timeoutSeconds; i++) {
+ if (condition.getAsBoolean()) {
+ return true;
+ }
+ TimeUnit.SECONDS.sleep(1);
+ }
+ return false;
+ }
Review Comment:
```suggestion
/**
* Waits for a condition to be met within a specific timeout.
*
* @param condition The condition to poll.
* @param timeoutSeconds Maximum time to wait in seconds.
* @param errorMessage The message to display if the timeout is reached.
* @throws InterruptedException if the sleep is interrupted.
* @throws AssertionError if the condition is not met within the timeout.
*/
public static void waitUntil(BooleanSupplier condition, int timeoutSeconds,
String errorMessage)
throws InterruptedException {
long limit = System.currentTimeMillis() + (timeoutSeconds * 1000L);
while (System.currentTimeMillis() < limit) {
if (condition.getAsBoolean()) {
return; // Condition met, exit early
}
TimeUnit.MILLISECONDS.sleep(500);
}
// Fail the test with a descriptive message
throw new AssertionError(errorMessage + " (timeout: " + timeoutSeconds +
"s)");
}
```
Nit: use while loop + epoch comparison, add error message.
##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/compact/ITTestHoodieFlinkCompactor.java:
##########
@@ -313,9 +315,7 @@ public void testHoodieFlinkCompactorService(boolean
enableChangelog) throws Exce
HoodieFlinkCompactor.AsyncCompactionService asyncCompactionService = new
HoodieFlinkCompactor.AsyncCompactionService(cfg, conf);
asyncCompactionService.start(null);
- // wait for the asynchronous commit to finish
- TimeUnit.SECONDS.sleep(10);
-
+ TestUtils.waitUntil(() ->
TestUtils.getLastCompleteInstant(tempFile.getAbsolutePath(),
HoodieTimeline.COMMIT_ACTION) != null, 20);
Review Comment:
```suggestion
assertTrue(TestUtils.waitUntil(() ->
TestUtils.getLastCompleteInstant(tempFile.getAbsolutePath(),
HoodieTimeline.COMMIT_ACTION) != null, 20),
"Timed out waiting for compaction commit");
```
Nit: Add ability to supply a message.
--
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]