From c4668813d06e334ad268f093c1717aebbc6cf8b3 Mon Sep 17 00:00:00 2001 From: Ioannis Kakavas Date: Thu, 26 Mar 2020 17:10:11 +0200 Subject: [PATCH] Improve stability of SamlServiceProviderIndexTests (#54241) (#54271) This test assumed cluster events would be processed quickly which is not always true Backport of: #54166 Co-authored-by: Tim Vernum --- .../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 8d16d2f9a31d0..6d5e9c895185d 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 void testWritesViaAliasIfItExists() { 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 void testInstallTemplateAutomaticallyOnDocumentWrite() { 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);