Skip to content

Commit fcd708f

Browse files
authored
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.
1 parent 8f43c75 commit fcd708f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,14 @@ public void testAddWithoutEnsembleTracker() throws Exception {
256256

257257
@Test
258258
public void testAdd() throws Exception {
259-
try (CuratorFramework client = newClient()) {
259+
CountDownLatch ensembleLatch = new CountDownLatch(1);
260+
try (CuratorFramework client = newClient(cluster.getConnectString(), ensembleLatch)) {
260261
client.start();
261262

262263
QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
263264
assertConfig(oldConfig, cluster.getInstances());
264265

265-
CountDownLatch latch = setChangeWaiter(client);
266+
CountDownLatch eventLatch = setChangeWaiter(client);
266267
try (TestingCluster newCluster = new TestingCluster(TestingCluster.makeSpecs(1, false))) {
267268
newCluster.start();
268269

@@ -271,7 +272,8 @@ public void testAdd() throws Exception {
271272
.fromConfig(oldConfig.getVersion())
272273
.forEnsemble();
273274

274-
assertTrue(timing.awaitLatch(latch));
275+
assertTrue(timing.awaitLatch(eventLatch));
276+
assertTrue(timing.awaitLatch(ensembleLatch));
275277

276278
byte[] newConfigData = client.getConfig().forEnsemble();
277279
QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
@@ -286,13 +288,14 @@ public void testAdd() throws Exception {
286288

287289
@Test
288290
public void testAddAsync() throws Exception {
289-
try (CuratorFramework client = newClient()) {
291+
CountDownLatch ensembleLatch = new CountDownLatch(1);
292+
try (CuratorFramework client = newClient(cluster.getConnectString(), ensembleLatch)) {
290293
client.start();
291294

292295
QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
293296
assertConfig(oldConfig, cluster.getInstances());
294297

295-
CountDownLatch latch = setChangeWaiter(client);
298+
CountDownLatch eventLatch = setChangeWaiter(client);
296299
try (TestingCluster newCluster = new TestingCluster(TestingCluster.makeSpecs(1, false))) {
297300
newCluster.start();
298301

@@ -312,7 +315,8 @@ public void processResult(CuratorFramework client, CuratorEvent event) throws Ex
312315
.forEnsemble();
313316

314317
assertTrue(timing.awaitLatch(callbackLatch));
315-
assertTrue(timing.awaitLatch(latch));
318+
assertTrue(timing.awaitLatch(eventLatch));
319+
assertTrue(timing.awaitLatch(ensembleLatch));
316320

317321
byte[] newConfigData = client.getConfig().forEnsemble();
318322
QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
@@ -327,13 +331,14 @@ public void processResult(CuratorFramework client, CuratorEvent event) throws Ex
327331

328332
@Test
329333
public void testAddAndRemove() throws Exception {
330-
try (CuratorFramework client = newClient()) {
334+
CountDownLatch ensembleLatch = new CountDownLatch(1);
335+
try (CuratorFramework client = newClient(cluster.getConnectString(), ensembleLatch)) {
331336
client.start();
332337

333338
QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
334339
assertConfig(oldConfig, cluster.getInstances());
335340

336-
CountDownLatch latch = setChangeWaiter(client);
341+
CountDownLatch eventLatch = setChangeWaiter(client);
337342

338343
try (TestingCluster newCluster = new TestingCluster(TestingCluster.makeSpecs(1, false))) {
339344
newCluster.start();
@@ -355,7 +360,8 @@ public void testAddAndRemove() throws Exception {
355360
.fromConfig(oldConfig.getVersion())
356361
.forEnsemble();
357362

358-
assertTrue(timing.awaitLatch(latch));
363+
assertTrue(timing.awaitLatch(eventLatch));
364+
assertTrue(timing.awaitLatch(ensembleLatch));
359365

360366
byte[] newConfigData = client.getConfig().forEnsemble();
361367
QuorumVerifier newConfig = toQuorumVerifier(newConfigData);

0 commit comments

Comments
 (0)