Skip to content

Commit c3ea8df

Browse files
authored
Remove race in ensure remote connection test (#72961)
Currently RemoteClusterConnectionTests#testEnsureConnected uses the same countdown latch for two ensure connected method calls. This introduces a race where the test ends before the second ensure connected method executes. This causes an exception to be thrown and the test to fail. This commit resolves the issue by adding a second latch. Fixes #71519.
1 parent 38cbf10 commit c3ea8df

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ public void testEnsureConnected() throws IOException, InterruptedException {
11701170
assertFalse(connectionManager.nodeConnected(seedNode));
11711171
assertFalse(connectionManager.nodeConnected(discoverableNode));
11721172
assertTrue(connection.assertNoRunningConnections());
1173-
CountDownLatch latch = new CountDownLatch(1);
1173+
CountDownLatch firstLatch = new CountDownLatch(1);
11741174
connection.ensureConnected(new LatchedActionListener<>(new ActionListener<Void>() {
11751175
@Override
11761176
public void onResponse(Void aVoid) {
@@ -1180,12 +1180,13 @@ public void onResponse(Void aVoid) {
11801180
public void onFailure(Exception e) {
11811181
throw new AssertionError(e);
11821182
}
1183-
}, latch));
1184-
latch.await();
1183+
}, firstLatch));
1184+
firstLatch.await();
11851185
assertTrue(connectionManager.nodeConnected(seedNode));
11861186
assertTrue(connectionManager.nodeConnected(discoverableNode));
11871187
assertTrue(connection.assertNoRunningConnections());
11881188

1189+
CountDownLatch secondLatch = new CountDownLatch(1);
11891190
// exec again we are already connected
11901191
connection.ensureConnected(new LatchedActionListener<>(new ActionListener<Void>() {
11911192
@Override
@@ -1196,8 +1197,8 @@ public void onResponse(Void aVoid) {
11961197
public void onFailure(Exception e) {
11971198
throw new AssertionError(e);
11981199
}
1199-
}, latch));
1200-
latch.await();
1200+
}, secondLatch));
1201+
secondLatch.await();
12011202
assertTrue(connectionManager.nodeConnected(seedNode));
12021203
assertTrue(connectionManager.nodeConnected(discoverableNode));
12031204
assertTrue(connection.assertNoRunningConnections());

0 commit comments

Comments
 (0)