Skip to content

Commit b869c2c

Browse files
authored
Fixed hanging test cases when failed to download ZK image that due to timeout or other problems (#15693)
* Close CuratorFramework before throwing IllegalStateException to avoid re-connecting ZK infinitely * Check whether WatchDog is used or not to avoid hanging at destroyProcess
1 parent 872c8cb commit b869c2c

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/main/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public List<ACL> getAclForPath(String path) {
9898
boolean connected = client.blockUntilConnected(timeout, TimeUnit.MILLISECONDS);
9999

100100
if (!connected) {
101+
// close CuratorFramework to stop re-connection.
102+
client.close();
101103
IllegalStateException illegalStateException =
102104
new IllegalStateException("zookeeper not connected, the address is: " + url);
103105

dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperWindowsContext.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public class ZookeeperWindowsContext extends ZookeeperContext {
4949
*/
5050
private final ExecuteWatchdog WATCHDOG = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
5151

52+
/**
53+
* Set it to TRUE when using WatchDog.
54+
*/
55+
private boolean usedWatchDog = false;
56+
5257
/**
5358
* The map to store the pair of clientPort and PID.
5459
*/
@@ -93,6 +98,7 @@ public ExecutorService getExecutorService() {
9398
* Returns the {@link ExecuteWatchdog}.
9499
*/
95100
public ExecuteWatchdog getWatchdog() {
101+
usedWatchDog = true;
96102
return WATCHDOG;
97103
}
98104

@@ -101,7 +107,10 @@ public ExecuteWatchdog getWatchdog() {
101107
*/
102108
public void destroy() {
103109
this.processIds.clear();
104-
this.WATCHDOG.destroyProcess();
110+
// check WatchDog used flag to avoid hanging at destroyProcess when WatchDog is not used.
111+
if (usedWatchDog) {
112+
this.WATCHDOG.destroyProcess();
113+
}
105114
try {
106115
DEFAULT_EXECUTOR_SERVICE.shutdownNow();
107116
} catch (SecurityException | NullPointerException ex) {

dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ResetZookeeperProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public void process(Context context) throws DubboTestException {
4545
client.start();
4646
boolean connected = client.blockUntilConnected(1000, TimeUnit.MILLISECONDS);
4747
if (!connected) {
48+
// close CuratorFramework to stop re-connection.
49+
client.close();
4850
throw new IllegalStateException("zookeeper not connected");
4951
}
5052
client.delete().deletingChildrenIfNeeded().forPath("/dubbo");

0 commit comments

Comments
 (0)