This is an automated email from the ASF dual-hosted git repository.

FrankChen021 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new df133e4687c test: fix flaky test EmbeddedDartReportApiTest (#19905)
df133e4687c is described below

commit df133e4687cf661a9ce286f9d5bce5c25141c734
Author: Frank Chen <[email protected]>
AuthorDate: Tue Sep 8 09:56:52 2026 +0800

    test: fix flaky test EmbeddedDartReportApiTest (#19905)
    
    * test: wait for completed Dart reports
    
    * test: use shared waiter for Dart reports
---
 .../embedded/msq/EmbeddedDartReportApiTest.java    | 40 ++++++++++++++++++----
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git 
a/embedded-tests/src/test/java/org/apache/druid/testing/embedded/msq/EmbeddedDartReportApiTest.java
 
b/embedded-tests/src/test/java/org/apache/druid/testing/embedded/msq/EmbeddedDartReportApiTest.java
index 85371b7ed9f..9a29f1bc194 100644
--- 
a/embedded-tests/src/test/java/org/apache/druid/testing/embedded/msq/EmbeddedDartReportApiTest.java
+++ 
b/embedded-tests/src/test/java/org/apache/druid/testing/embedded/msq/EmbeddedDartReportApiTest.java
@@ -72,7 +72,6 @@ import org.junit.jupiter.api.Timeout;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -227,7 +226,7 @@ public class EmbeddedDartReportApiTest extends 
EmbeddedClusterTestBase
     Assertions.assertEquals("10", result);
 
     // Now fetch the report using the SQL query ID
-    final GetQueryReportResponse reportResponse = 
msqApis.getDartQueryReport(sqlQueryId, broker1);
+    final GetQueryReportResponse reportResponse = 
waitForCompletedReports(sqlQueryId, broker1).get(0);
 
     // Verify the report response
     Assertions.assertNotNull(reportResponse, "Report response should not be 
null");
@@ -332,12 +331,12 @@ public class EmbeddedDartReportApiTest extends 
EmbeddedClusterTestBase
     Assertions.assertEquals(1, sqlClients1.getAllClients().size(), "Broker1 
should have 1 client (broker2)");
     Assertions.assertEquals(1, sqlClients2.getAllClients().size(), "Broker2 
should have 1 client (broker1)");
 
-    // Fetch the report from both brokers, to verify cross-broker lookup is 
working
-    final GetQueryReportResponse reportFromBroker1 = 
msqApis.getDartQueryReport(sqlQueryId, broker1);
-    final GetQueryReportResponse reportFromBroker2 = 
msqApis.getDartQueryReport(sqlQueryId, broker2);
+    // Wait for the completed report to be available from both brokers. The 
SQL result can be returned
+    // before the controller is deregistered and its completed report is 
published.
+    final List<GetQueryReportResponse> completedReports = 
waitForCompletedReports(sqlQueryId, broker1, broker2);
 
     // Verify the report content
-    for (GetQueryReportResponse report : Arrays.asList(reportFromBroker1, 
reportFromBroker2)) {
+    for (GetQueryReportResponse report : completedReports) {
       Assertions.assertNotNull(report);
       final DartQueryInfo queryInfo = (DartQueryInfo) report.getQueryInfo();
       Assertions.assertEquals(sqlQueryId, queryInfo.getSqlQueryId());
@@ -602,6 +601,35 @@ public class EmbeddedDartReportApiTest extends 
EmbeddedClusterTestBase
     throw new ISE("Timed out after[%,d] ms waiting for query to be in RUNNING 
state", timeout);
   }
 
+  /**
+   * Polls the report API on the specified brokers until completed reports are 
available from all of them.
+   */
+  private List<GetQueryReportResponse> waitForCompletedReports(
+      final String sqlQueryId,
+      final EmbeddedBroker... targetBrokers
+  )
+  {
+    final long timeout = 30_000;
+    return cluster.callApi()
+                  .waitForResult(
+                      () -> {
+                        final List<GetQueryReportResponse> reports = new 
ArrayList<>(targetBrokers.length);
+                        for (final EmbeddedBroker targetBroker : 
targetBrokers) {
+                          reports.add(msqApis.getDartQueryReport(sqlQueryId, 
targetBroker));
+                        }
+                        return reports;
+                      },
+                      reports -> reports.stream().allMatch(
+                          report -> report != null
+                                    && report.getQueryInfo() instanceof 
DartQueryInfo queryInfo
+                                    && queryInfo.getDurationMs() != null
+                      )
+                  )
+                  .withTimeoutMillis(timeout)
+                  .withRetryMillis(100)
+                  .go();
+  }
+
   /**
    * Gets running queries from {@link #broker1} using the provided HTTP client 
for authentication.
    */


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to