From f0a757cebc49e2cacf621c613e7339f5f0f2b939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slobodan=20Adamovi=C4=87?= Date: Mon, 17 Feb 2025 22:12:21 +0100 Subject: [PATCH] [Test] Fix QueryableReservedRolesIT testQueryDeleteOrUpdateReservedRoles (#122803) 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 https://github.com/elastic/elasticsearch/issues/120401 --- .../security/QueryableReservedRolesIT.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryableReservedRolesIT.java b/x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryableReservedRolesIT.java index 7adff21d8df4f..e8363cad4a68b 100644 --- a/x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryableReservedRolesIT.java +++ b/x-pack/plugin/security/qa/security-basic/src/javaRestTest/java/org/elasticsearch/xpack/security/QueryableReservedRolesIT.java @@ -121,14 +121,16 @@ public void testQueryDeleteOrUpdateReservedRoles() throws Exception { waitForMigrationCompletion(adminClient(), SecurityMigrations.ROLE_METADATA_FLATTENED_MIGRATION_VERSION); final String[] allReservedRoles = ReservedRolesStore.names().toArray(new String[0]); - assertQuery(client(), """ - { "query": { "bool": { "must": { "term": { "metadata._reserved": true } } } }, "size": 100 } - """, allReservedRoles.length, roles -> { - assertThat(roles, iterableWithSize(allReservedRoles.length)); - for (var role : roles) { - assertThat((String) role.get("name"), is(oneOf(allReservedRoles))); - } - }); + assertBusy(() -> { + assertQuery(client(), """ + { "query": { "bool": { "must": { "term": { "metadata._reserved": true } } } }, "size": 100 } + """, allReservedRoles.length, roles -> { + assertThat(roles, iterableWithSize(allReservedRoles.length)); + for (var role : roles) { + assertThat((String) role.get("name"), is(oneOf(allReservedRoles))); + } + }); + }, 30, TimeUnit.SECONDS); final String roleName = randomFrom(allReservedRoles); assertQuery(client(), String.format("""