Skip to content

Commit c466881

Browse files
jkakavastvernum
andauthored
Improve stability of SamlServiceProviderIndexTests (elastic#54241) (elastic#54271)
This test assumed cluster events would be processed quickly which is not always true Backport of: elastic#54166 Co-authored-by: Tim Vernum <[email protected]>
1 parent 20e821e commit c466881

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderIndexTests.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,16 @@ public void testWritesViaAliasIfItExists() {
162162
assertThat(readDocument(document.docId), equalTo(document));
163163
}
164164

165-
public void testInstallTemplateAutomaticallyOnClusterChange() {
165+
public void testInstallTemplateAutomaticallyOnClusterChange() throws Exception {
166166
// Create an index that will trigger a cluster state change
167-
client().admin().indices().create(new CreateIndexRequest(randomAlphaOfLength(7).toLowerCase(Locale.ROOT))).actionGet();
167+
final String indexName = randomAlphaOfLength(7).toLowerCase(Locale.ROOT);
168+
client().admin().indices().create(new CreateIndexRequest(indexName)).actionGet();
169+
170+
ensureGreen(indexName);
168171

169172
IndexTemplateMetaData templateMeta = clusterService.state().metaData().templates().get(SamlServiceProviderIndex.TEMPLATE_NAME);
170-
assertNotNull(templateMeta);
173+
174+
assertBusy(() -> assertThat("template should have been installed", templateMeta, notNullValue()));
171175

172176
final PlainActionFuture<Boolean> installTemplate = new PlainActionFuture<>();
173177
serviceProviderIndex.installIndexTemplate(installTemplate);
@@ -181,7 +185,7 @@ public void testInstallTemplateAutomaticallyOnDocumentWrite() {
181185
assertThat(readDocument(doc.docId), equalTo(doc));
182186

183187
IndexTemplateMetaData templateMeta = clusterService.state().metaData().templates().get(SamlServiceProviderIndex.TEMPLATE_NAME);
184-
assertNotNull(templateMeta);
188+
assertThat("template should have been installed", templateMeta, notNullValue());
185189

186190
final PlainActionFuture<Boolean> installTemplate = new PlainActionFuture<>();
187191
serviceProviderIndex.installIndexTemplate(installTemplate);

0 commit comments

Comments
 (0)