Skip to content

Commit 9d8b957

Browse files
authored
[Test] More robust order of assertions (#99461) (#99468)
This PR adjusts the order of assertions to ensure we are done with the atomic reference variable in the previous assertions before changing it to null. Resolves: #99406
1 parent 082350a commit 9d8b957

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransportAuthenticationTests.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,12 @@ public void testProxyStrategyConnectionClosesWhenAuthenticatorAlwaysFails() thro
202202
fail("No connection should be available if authn fails");
203203
}, e -> {
204204
logger.info("Expected: no connection could not be established");
205-
connectionTestDone.countDown();
206-
assertThat(e, instanceOf(RemoteTransportException.class));
207-
assertThat(e.getCause(), instanceOf(authenticationException.get().getClass()));
205+
try {
206+
assertThat(e, instanceOf(RemoteTransportException.class));
207+
assertThat(e.getCause(), instanceOf(authenticationException.get().getClass()));
208+
} finally {
209+
connectionTestDone.countDown();
210+
}
208211
}));
209212
assertTrue(connectionTestDone.await(10L, TimeUnit.SECONDS));
210213
}
@@ -259,9 +262,12 @@ public void testSniffStrategyNoConnectionWhenAuthenticatorAlwaysFails() throws E
259262
fail("No connection should be available if authn fails");
260263
}, e -> {
261264
logger.info("Expected: no connection could be established");
262-
connectionTestDone.countDown();
263-
assertThat(e, instanceOf(RemoteTransportException.class));
264-
assertThat(e.getCause(), instanceOf(authenticationException.get().getClass()));
265+
try {
266+
assertThat(e, instanceOf(RemoteTransportException.class));
267+
assertThat(e.getCause(), instanceOf(authenticationException.get().getClass()));
268+
} finally {
269+
connectionTestDone.countDown();
270+
}
265271
}));
266272
assertTrue(connectionTestDone.await(10L, TimeUnit.SECONDS));
267273
}

0 commit comments

Comments
 (0)