This is an automated email from the ASF dual-hosted git repository.

kezhuw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git


The following commit(s) were added to refs/heads/master by this push:
     new fcd708fb3 Fix flaky tests in TestReconfiguration (#1271)
fcd708fb3 is described below

commit fcd708fb3aa99d8c30e8ad14684afc1fe34173d1
Author: Kezhu Wang <[email protected]>
AuthorDate: Fri Jul 4 10:59:33 2025 +0800

    Fix flaky tests in TestReconfiguration (#1271)
    
    `testAdd`, `testAddAsync` and `testAddAndRemove` asserts that
    `EnsembleProvider::setConnectionString` is updated with new connect
    string after ensemble changed. Since the update is asynchronous, so they
    should wait before assertion.
---
 .../framework/imps/TestReconfiguration.java        | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git 
a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
 
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index 11a17421d..74f6850d1 100644
--- 
a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ 
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -256,13 +256,14 @@ public class TestReconfiguration extends CuratorTestBase {
 
     @Test
     public void testAdd() throws Exception {
-        try (CuratorFramework client = newClient()) {
+        CountDownLatch ensembleLatch = new CountDownLatch(1);
+        try (CuratorFramework client = newClient(cluster.getConnectString(), 
ensembleLatch)) {
             client.start();
 
             QuorumVerifier oldConfig = 
toQuorumVerifier(client.getConfig().forEnsemble());
             assertConfig(oldConfig, cluster.getInstances());
 
-            CountDownLatch latch = setChangeWaiter(client);
+            CountDownLatch eventLatch = setChangeWaiter(client);
             try (TestingCluster newCluster = new 
TestingCluster(TestingCluster.makeSpecs(1, false))) {
                 newCluster.start();
 
@@ -271,7 +272,8 @@ public class TestReconfiguration extends CuratorTestBase {
                         .fromConfig(oldConfig.getVersion())
                         .forEnsemble();
 
-                assertTrue(timing.awaitLatch(latch));
+                assertTrue(timing.awaitLatch(eventLatch));
+                assertTrue(timing.awaitLatch(ensembleLatch));
 
                 byte[] newConfigData = client.getConfig().forEnsemble();
                 QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
@@ -286,13 +288,14 @@ public class TestReconfiguration extends CuratorTestBase {
 
     @Test
     public void testAddAsync() throws Exception {
-        try (CuratorFramework client = newClient()) {
+        CountDownLatch ensembleLatch = new CountDownLatch(1);
+        try (CuratorFramework client = newClient(cluster.getConnectString(), 
ensembleLatch)) {
             client.start();
 
             QuorumVerifier oldConfig = 
toQuorumVerifier(client.getConfig().forEnsemble());
             assertConfig(oldConfig, cluster.getInstances());
 
-            CountDownLatch latch = setChangeWaiter(client);
+            CountDownLatch eventLatch = setChangeWaiter(client);
             try (TestingCluster newCluster = new 
TestingCluster(TestingCluster.makeSpecs(1, false))) {
                 newCluster.start();
 
@@ -312,7 +315,8 @@ public class TestReconfiguration extends CuratorTestBase {
                         .forEnsemble();
 
                 assertTrue(timing.awaitLatch(callbackLatch));
-                assertTrue(timing.awaitLatch(latch));
+                assertTrue(timing.awaitLatch(eventLatch));
+                assertTrue(timing.awaitLatch(ensembleLatch));
 
                 byte[] newConfigData = client.getConfig().forEnsemble();
                 QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
@@ -327,13 +331,14 @@ public class TestReconfiguration extends CuratorTestBase {
 
     @Test
     public void testAddAndRemove() throws Exception {
-        try (CuratorFramework client = newClient()) {
+        CountDownLatch ensembleLatch = new CountDownLatch(1);
+        try (CuratorFramework client = newClient(cluster.getConnectString(), 
ensembleLatch)) {
             client.start();
 
             QuorumVerifier oldConfig = 
toQuorumVerifier(client.getConfig().forEnsemble());
             assertConfig(oldConfig, cluster.getInstances());
 
-            CountDownLatch latch = setChangeWaiter(client);
+            CountDownLatch eventLatch = setChangeWaiter(client);
 
             try (TestingCluster newCluster = new 
TestingCluster(TestingCluster.makeSpecs(1, false))) {
                 newCluster.start();
@@ -355,7 +360,8 @@ public class TestReconfiguration extends CuratorTestBase {
                         .fromConfig(oldConfig.getVersion())
                         .forEnsemble();
 
-                assertTrue(timing.awaitLatch(latch));
+                assertTrue(timing.awaitLatch(eventLatch));
+                assertTrue(timing.awaitLatch(ensembleLatch));
 
                 byte[] newConfigData = client.getConfig().forEnsemble();
                 QuorumVerifier newConfig = toQuorumVerifier(newConfigData);

Reply via email to