Improve stability of SamlServiceProviderIndexTests (#54241)

This test assumed cluster events would be processed quickly which is
not always true

Backport of: #54166
This commit is contained in:
Tim Vernum 2020-03-26 14:07:42 +11:00 committed by GitHub
parent fe8257d981
commit 1fc518c25e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -162,12 +162,16 @@ public class SamlServiceProviderIndexTests extends ESSingleNodeTestCase {
assertThat(readDocument(document.docId), equalTo(document)); assertThat(readDocument(document.docId), equalTo(document));
} }
public void testInstallTemplateAutomaticallyOnClusterChange() { public void testInstallTemplateAutomaticallyOnClusterChange() throws Exception {
// Create an index that will trigger a cluster state change // 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); IndexTemplateMetaData templateMeta = clusterService.state().metaData().templates().get(SamlServiceProviderIndex.TEMPLATE_NAME);
assertNotNull(templateMeta);
assertBusy(() -> assertThat("template should have been installed", templateMeta, notNullValue()));
final PlainActionFuture<Boolean> installTemplate = new PlainActionFuture<>(); final PlainActionFuture<Boolean> installTemplate = new PlainActionFuture<>();
serviceProviderIndex.installIndexTemplate(installTemplate); serviceProviderIndex.installIndexTemplate(installTemplate);
@ -181,7 +185,7 @@ public class SamlServiceProviderIndexTests extends ESSingleNodeTestCase {
assertThat(readDocument(doc.docId), equalTo(doc)); assertThat(readDocument(doc.docId), equalTo(doc));
IndexTemplateMetaData templateMeta = clusterService.state().metaData().templates().get(SamlServiceProviderIndex.TEMPLATE_NAME); IndexTemplateMetaData templateMeta = clusterService.state().metaData().templates().get(SamlServiceProviderIndex.TEMPLATE_NAME);
assertNotNull(templateMeta); assertThat("template should have been installed", templateMeta, notNullValue());
final PlainActionFuture<Boolean> installTemplate = new PlainActionFuture<>(); final PlainActionFuture<Boolean> installTemplate = new PlainActionFuture<>();
serviceProviderIndex.installIndexTemplate(installTemplate); serviceProviderIndex.installIndexTemplate(installTemplate);