Skip to content

Commit

Permalink
Remove race in ensure remote connection test (#72961)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tim-Brooks authored Jun 9, 2021
1 parent 38cbf10 commit c3ea8df
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ public void testEnsureConnected() throws IOException, InterruptedException {
assertFalse(connectionManager.nodeConnected(seedNode));
assertFalse(connectionManager.nodeConnected(discoverableNode));
assertTrue(connection.assertNoRunningConnections());
CountDownLatch latch = new CountDownLatch(1);
CountDownLatch firstLatch = new CountDownLatch(1);
connection.ensureConnected(new LatchedActionListener<>(new ActionListener<Void>() {
@Override
public void onResponse(Void aVoid) {
Expand All @@ -1180,12 +1180,13 @@ public void onResponse(Void aVoid) {
public void onFailure(Exception e) {
throw new AssertionError(e);
}
}, latch));
latch.await();
}, firstLatch));
firstLatch.await();
assertTrue(connectionManager.nodeConnected(seedNode));
assertTrue(connectionManager.nodeConnected(discoverableNode));
assertTrue(connection.assertNoRunningConnections());

CountDownLatch secondLatch = new CountDownLatch(1);
// exec again we are already connected
connection.ensureConnected(new LatchedActionListener<>(new ActionListener<Void>() {
@Override
Expand All @@ -1196,8 +1197,8 @@ public void onResponse(Void aVoid) {
public void onFailure(Exception e) {
throw new AssertionError(e);
}
}, latch));
latch.await();
}, secondLatch));
secondLatch.await();
assertTrue(connectionManager.nodeConnected(seedNode));
assertTrue(connectionManager.nodeConnected(discoverableNode));
assertTrue(connection.assertNoRunningConnections());
Expand Down

0 comments on commit c3ea8df

Please sign in to comment.