FrankChen021 commented on code in PR #19603:
URL: https://github.com/apache/druid/pull/19603#discussion_r3452104533


##########
server/src/test/java/org/apache/druid/metadata/SqlSegmentsMetadataManagerTest.java:
##########
@@ -231,6 +233,51 @@ public void testPollPeriodicallyAndOnDemandInterleave() 
throws Exception
     );
   }
 
+  @Test(timeout = 30_000)
+  public void testForceOrWait_blocksUntilConcurrentPollCompletes() throws 
Exception
+  {
+    Field lockField = 
SqlSegmentsMetadataManager.class.getDeclaredField("startStopPollLock");
+    lockField.setAccessible(true);
+    ReentrantReadWriteLock rwLock = (ReentrantReadWriteLock) 
lockField.get(sqlSegmentsMetadataManager);
+
+    Field pollField = 
SqlSegmentsMetadataManager.class.getDeclaredField("latestDatabasePoll");
+    pollField.setAccessible(true);
+
+    Thread caller = new Thread(() -> 
sqlSegmentsMetadataManager.forceOrWaitOngoingDatabasePoll());
+    caller.setDaemon(true);
+
+    SqlSegmentsMetadataManager.OnDemandDatabasePoll concurrentPoll;
+
+    rwLock.writeLock().lock();
+    try {
+      caller.start();
+      // Allow the caller to capture checkStartTimeNanos and block on the 
write lock.
+      Thread.sleep(100);

Review Comment:
   [P3] Replace timing sleep with deterministic thread coordination
   
   The new regression test depends on the caller thread being scheduled within 
this fixed 100 ms window so it captures checkStartTimeNanos before 
concurrentPoll is created. On a slow or overloaded CI worker, the caller can 
start after the sleep, making concurrentPoll.initiationTimeNanos <= 
checkStartTimeNanos; then the production branch under test is skipped and the 
caller may run its own poll or return early, causing a flaky failure or a false 
pass. Please coordinate on the lock queue/state, e.g. wait until the caller is 
queued on the write lock before creating concurrentPoll, instead of relying on 
sleep timing.



-- 
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]


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

Reply via email to