LI123456mo commented on code in PR #15979:
URL: https://github.com/apache/dubbo/pull/15979#discussion_r2674705968


##########
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java:
##########
@@ -70,15 +70,32 @@ protected void doProcess(ZookeeperWindowsContext context) 
throws DubboTestExcept
                     .toString());
             context.getExecutorService().submit(() -> 
executor.execute(cmdLine));
         }
-        try {
-            // TODO: Help me to optimize the ugly sleep.
-            // sleep to wait all of zookeeper instances are started 
successfully.
-            // The best way is to check the output log with the specified 
keywords,
-            // however, there maybe keep waiting for check when any exception 
occurred,
-            // because the output stream will be blocked to wait for 
continuous data without any break
-            TimeUnit.SECONDS.sleep(3);
-        } catch (InterruptedException e) {
-            // ignored
+
+        // optimized the sleep by pulling the ports untill they are ready.
+        // This avoids waiting the full 3 seconds if the instances start 
quickly,
+        // and provide a safer timeout mechanism than blocking on log output 
streams
+        for (int clientPort : context.getClientPorts()) {
+            boolean started = false;
+            long timeout = System.currentTimeMillis() + 10000; // 10 seconds 
max wait
+
+            while (System.currentTimeMillis() < timeout) {

Review Comment:
   Hi @zrlw, thank you for the feedback! I used the Socket polling approach 
because we are waiting for an external Zookeeper process to open its port.
   
   Could you clarify if there is a specific Dubbo utility or a shared Condition 
in ZookeeperWindowsContext I should be using instead? I'm happy to refactor it 
to match the project's preferred pattern!



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