From 1e39663bdaf8f6b1406b917be6eb8594ad173ee0 Mon Sep 17 00:00:00 2001 From: Surya Srinivasan Date: Sun, 15 Feb 2026 00:51:06 +0530 Subject: [PATCH] [Improvement] Replace fixed sleep with Curator readiness check in StartZookeeperWindowsProcessor --- .../StartZookeeperWindowsProcessor.java | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java index f384ede4ed4..37b47d3595b 100644 --- a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java @@ -29,6 +29,9 @@ import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.Executor; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.RetryOneTime; /** * Create {@link Process} to start zookeeper on Windows OS. @@ -70,15 +73,39 @@ protected void doProcess(ZookeeperWindowsContext context) throws DubboTestExcept .toString()); context.getExecutorService().submit(() -> executor.execute(cmdLine)); } + logger.info("Waiting for all Zookeeper instances to be ready..."); + for (int clientPort : context.getClientPorts()) { + waitForZookeeperReady(clientPort); + } + } + + private void waitForZookeeperReady(int port) throws DubboTestException { + String connectString = "127.0.0.1:" + port; + + CuratorFramework client = CuratorFrameworkFactory.builder() + .connectString(connectString) + .retryPolicy(new RetryOneTime(1000)) + .connectionTimeoutMs(5000) + .sessionTimeoutMs(5000) + .build(); + 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); + logger.info("Waiting for Zookeeper to be ready at {}", connectString); + + client.start(); + boolean connected = client.blockUntilConnected(10, TimeUnit.SECONDS); + + if (!connected) { + throw new DubboTestException("Zookeeper startup timeout at " + connectString); + } + + logger.info("Zookeeper is ready at {}", connectString); + } catch (InterruptedException e) { - // ignored + Thread.currentThread().interrupt(); + throw new DubboTestException("Interrupted while waiting for Zookeeper startup at " + connectString, e); + } finally { + client.close(); } } }