Skip to content

Commit 8172440

Browse files
[Test] Fix QueryableReservedRolesIT testQueryDeleteOrUpdateReservedRoles (elastic#122803) (elastic#122807)
Adds missing `assertBusy` in `testQueryDeleteOrUpdateReservedRoles`. We wait for security migration to finish before test execution, but this is not enough to guarantee that built-in roles are synchronized into the `.security` index. In many cases, the roles have already been synchronized before the query gets executed, but in rare cases the cluster is a bit slower and the assertion fails because the built-in roles have not been indexed yet. Resolves elastic#120401
1 parent 47139ec commit 8172440

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryableReservedRolesIT.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,16 @@ public void testQueryDeleteOrUpdateReservedRoles() throws Exception {
121121
waitForMigrationCompletion(adminClient(), SecurityMigrations.ROLE_METADATA_FLATTENED_MIGRATION_VERSION);
122122

123123
final String[] allReservedRoles = ReservedRolesStore.names().toArray(new String[0]);
124-
assertQuery(client(), """
125-
{ "query": { "bool": { "must": { "term": { "metadata._reserved": true } } } }, "size": 100 }
126-
""", allReservedRoles.length, roles -> {
127-
assertThat(roles, iterableWithSize(allReservedRoles.length));
128-
for (var role : roles) {
129-
assertThat((String) role.get("name"), is(oneOf(allReservedRoles)));
130-
}
131-
});
124+
assertBusy(() -> {
125+
assertQuery(client(), """
126+
{ "query": { "bool": { "must": { "term": { "metadata._reserved": true } } } }, "size": 100 }
127+
""", allReservedRoles.length, roles -> {
128+
assertThat(roles, iterableWithSize(allReservedRoles.length));
129+
for (var role : roles) {
130+
assertThat((String) role.get("name"), is(oneOf(allReservedRoles)));
131+
}
132+
});
133+
}, 30, TimeUnit.SECONDS);
132134

133135
final String roleName = randomFrom(allReservedRoles);
134136
assertQuery(client(), String.format("""

0 commit comments

Comments
 (0)