From 1fc518c25e5854f0e6596377fa044db3c9b2fef8 Mon Sep 17 00:00:00 2001 From: Tim Vernum Date: Thu, 26 Mar 2020 14:07:42 +1100 Subject: [PATCH] Improve stability of SamlServiceProviderIndexTests (#54241) This test assumed cluster events would be processed quickly which is not always true Backport of: #54166 --- .../idp/saml/sp/SamlServiceProviderIndexTests.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndexTests.java b/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndexTests.java index 8d16d2f9a31..6d5e9c89518 100644 --- a/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndexTests.java +++ b/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndexTests.java @@ -162,12 +162,16 @@ public class SamlServiceProviderIndexTests extends ESSingleNodeTestCase { assertThat(readDocument(document.docId), equalTo(document)); } - public void testInstallTemplateAutomaticallyOnClusterChange() { + public void testInstallTemplateAutomaticallyOnClusterChange() throws Exception { // Create an index that will trigger a cluster state change - client().admin().indices().create(new CreateIndexRequest(randomAlphaOfLength(7).toLowerCase(Locale.ROOT))).actionGet(); + final String indexName = randomAlphaOfLength(7).toLowerCase(Locale.ROOT); + client().admin().indices().create(new CreateIndexRequest(indexName)).actionGet(); + + ensureGreen(indexName); IndexTemplateMetaData templateMeta = clusterService.state().metaData().templates().get(SamlServiceProviderIndex.TEMPLATE_NAME); - assertNotNull(templateMeta); + + assertBusy(() -> assertThat("template should have been installed", templateMeta, notNullValue())); final PlainActionFuture installTemplate = new PlainActionFuture<>(); serviceProviderIndex.installIndexTemplate(installTemplate); @@ -181,7 +185,7 @@ public class SamlServiceProviderIndexTests extends ESSingleNodeTestCase { assertThat(readDocument(doc.docId), equalTo(doc)); IndexTemplateMetaData templateMeta = clusterService.state().metaData().templates().get(SamlServiceProviderIndex.TEMPLATE_NAME); - assertNotNull(templateMeta); + assertThat("template should have been installed", templateMeta, notNullValue()); final PlainActionFuture installTemplate = new PlainActionFuture<>(); serviceProviderIndex.installIndexTemplate(installTemplate);