diff --git a/testsuite/elytron/src/test/java/org/wildfly/test/integration/elytron/sasl/mgmt/AbstractKerberosMgmtSaslTestBase.java b/testsuite/elytron/src/test/java/org/wildfly/test/integration/elytron/sasl/mgmt/AbstractKerberosMgmtSaslTestBase.java index 0ecb0d77100..38daef43c28 100644 --- a/testsuite/elytron/src/test/java/org/wildfly/test/integration/elytron/sasl/mgmt/AbstractKerberosMgmtSaslTestBase.java +++ b/testsuite/elytron/src/test/java/org/wildfly/test/integration/elytron/sasl/mgmt/AbstractKerberosMgmtSaslTestBase.java @@ -342,37 +342,19 @@ protected void assertAuthenticationFails(String message, Class System.currentTimeMillis()); - Throwable cause = e.getCause(); - assertThat("ConnectionException was expected as a cause when authentication fails", cause, - is(instanceOf(ConnectException.class))); - - // if execution ends with ClosedChannelException during first run, run once again - if (i == 0 && cause.getCause() instanceof ClosedChannelException) { - LOGGER.warn("ClosedChannelException detected, probably because of the bug in SSLEngine. Because this happens very rarely, attempt to execute the op again"); - continue; - } - assertThat("Unexpected type of inherited exception for authentication failure", cause.getCause(), - anyOf(is(instanceOf(SSLException.class)), is(instanceOf(SaslException.class)), - is(instanceOf(RedirectException.class)))); - } - // if execution succeeds, there is no need to run again - break; + final long startTime = System.currentTimeMillis(); + try { + executeWhoAmI(withTls); + fail(message); + } catch (IOException | GeneralSecurityException e) { + assertTrue("Connection reached its timeout (hang).", + startTime + CONNECTION_TIMEOUT_IN_MS > System.currentTimeMillis()); + Throwable cause = e.getCause(); + assertThat("ConnectionException was expected as a cause when authentication fails", cause, + is(instanceOf(ConnectException.class))); + assertThat("Unexpected type of inherited exception for authentication failure", cause.getCause(), + anyOf(is(instanceOf(SSLException.class)), is(instanceOf(SaslException.class)), + is(instanceOf(RedirectException.class)), is(instanceOf(ClosedChannelException.class)))); } }