Skip to content

Commit f9cba69

Browse files
committed
Fixes SecurityIntegTestCase so it always adds at least one alias
(#33296) * Fixes SecurityIntegTestCase so it always adds at least one alias `SecurityIntegTestCase.createIndicesWithRandomAliases` could randomly fail because its not gauranteed that the randomness of which aliases to add to the `IndicesAliasesRequestBuilder` would always select at least one alias to add. This change fixes the problem by keeping track of whether we have added an alias to teh request and forcing the last alias to be added if no other aliases have been added so far. Closes #30098 Closes #33123e * Addresses review comments
1 parent 867a10a commit f9cba69

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import io.netty.util.ThreadDeathWatcher;
99
import io.netty.util.concurrent.GlobalEventExecutor;
10+
1011
import org.elasticsearch.Version;
1112
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
1213
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
@@ -427,14 +428,18 @@ protected void createIndicesWithRandomAliases(String... indices) {
427428
createIndex(indices);
428429

429430
if (frequently()) {
431+
boolean aliasAdded = false;
430432
IndicesAliasesRequestBuilder builder = client().admin().indices().prepareAliases();
431433
for (String index : indices) {
432434
if (frequently()) {
433435
//one alias per index with prefix "alias-"
434436
builder.addAlias(index, "alias-" + index);
437+
aliasAdded = true;
435438
}
436439
}
437-
if (randomBoolean()) {
440+
// If we get to this point and we haven't added an alias to the request we need to add one
441+
// or the request will fail so use noAliasAdded to force adding the alias in this case
442+
if (aliasAdded == false || randomBoolean()) {
438443
//one alias pointing to all indices
439444
for (String index : indices) {
440445
builder.addAlias(index, "alias");

0 commit comments

Comments
 (0)