From 7b8d92a2a779c12aff4e8080d3bc80bb5caa9fd5 Mon Sep 17 00:00:00 2001 From: jaymode Date: Mon, 25 Sep 2017 13:02:22 -0600 Subject: [PATCH] Test: fix AuthenticationService tests timeouts due to incorrect stream sizes The AuthenticationService#testInvalidToken would cause a suite timeout in the case of an exception due to a incorrect stream size as the latch was never counted down. This fixes the missing latch countdown. relates elastic/x-pack-elasticsearch#2615 Original commit: elastic/x-pack-elasticsearch@e838e6e912560d04cabd4a6f3755c20b7c22ca58 --- .../xpack/security/authc/AuthenticationServiceTests.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/authc/AuthenticationServiceTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/authc/AuthenticationServiceTests.java index ba6b61d91d7..8a34e61cf5b 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/authc/AuthenticationServiceTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/authc/AuthenticationServiceTests.java @@ -830,6 +830,7 @@ public class AuthenticationServiceTests extends ESTestCase { random().nextBytes(randomBytes); final CountDownLatch latch = new CountDownLatch(1); final Authentication expected = new Authentication(user, new RealmRef(firstRealm.name(), firstRealm.type(), "authc_test"), null); + AtomicBoolean success = new AtomicBoolean(false); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.putHeader("Authorization", "Bearer " + Base64.getEncoder().encodeToString(randomBytes)); service.authenticate("_action", message, null, ActionListener.wrap(result -> { @@ -839,18 +840,22 @@ public class AuthenticationServiceTests extends ESTestCase { assertThat(result.getAuthenticatedBy(), is(notNullValue())); assertThreadContextContainsAuthentication(result); assertEquals(expected, result); + success.set(true); latch.countDown(); }, this::logAndFail)); } catch (IllegalArgumentException ex) { assertThat(ex.getMessage(), containsString("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: ")); + latch.countDown(); } catch (NegativeArraySizeException ex) { assertThat(ex.getMessage(), containsString("array size must be positive but was: ")); - + latch.countDown(); } // we need to use a latch here because the key computation goes async on another thread! latch.await(); - verify(auditTrail).authenticationSuccess(firstRealm.name(), user, "_action", message); + if (success.get()) { + verify(auditTrail).authenticationSuccess(firstRealm.name(), user, "_action", message); + } verifyNoMoreInteractions(auditTrail); }