zrlw commented on code in PR #15979:
URL: https://github.com/apache/dubbo/pull/15979#discussion_r2674872399
##########
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) {
+ try (java.net.Socket socket = new java.net.Socket("127.0.0.1",
clientPort)) {
Review Comment:
Timeout control mechanism is totally meaningless because the
```Socket(host,port)``` method will not return by default until the connection
is established or network error occurs.
--
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]