From 0bb532380bde46f7da3589c04118a0e0bff37a01 Mon Sep 17 00:00:00 2001 From: Tim Vernum Date: Thu, 28 Oct 2021 18:08:47 +1100 Subject: [PATCH] Wait 3 seconds for the server to reload trust (#79778) (#79988) Sometimes the final session seems to fail because it is still using the old trust configuration. This commit adds an assertBusy to give it time to settle. Resolves: #77024 --- .../security/authc/ldap/LdapSessionFactoryTests.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapSessionFactoryTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapSessionFactoryTests.java index 771caca12efd3..7f478ee604518 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapSessionFactoryTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapSessionFactoryTests.java @@ -38,6 +38,7 @@ import java.nio.file.StandardCopyOption; import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; @@ -294,10 +295,12 @@ public void testSslTrustIsReloaded() throws Exception { Files.copy(realCa, ldapCaPath, StandardCopyOption.REPLACE_EXISTING); resourceWatcher.notifyNow(ResourceWatcherService.Frequency.HIGH); - final LdapSession session = session(sessionFactory, user, userPass); - assertThat(session.userDn(), is("cn=Horatio Hornblower,ou=people,o=sevenSeas")); - - session.close(); + // Occasionally the reload doesn't take immediate effect so the next connection fails. + assertBusy(() -> { + final LdapSession session = session(sessionFactory, user, userPass); + assertThat(session.userDn(), is("cn=Horatio Hornblower,ou=people,o=sevenSeas")); + session.close(); + }, 3, TimeUnit.SECONDS); } } }