From 488184a2d01cc654e21ecfac7d27579509b91e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Fred=C3=A9n?= <109296772+jfreden@users.noreply.github.com> Date: Fri, 28 Nov 2025 09:47:13 +0100 Subject: [PATCH] Fix testRoleMigration race condition (#138742) --- .../SecurityIndexRolesMetadataMigrationIT.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/SecurityIndexRolesMetadataMigrationIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/SecurityIndexRolesMetadataMigrationIT.java index 4c03e5eadbd5c..054be443ba8e4 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/SecurityIndexRolesMetadataMigrationIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/SecurityIndexRolesMetadataMigrationIT.java @@ -63,8 +63,9 @@ public void testRoleMigration() throws Exception { assertMigratedDocInSecurityIndex(mixed1TestRole, "meta", "test"); assertMigratedDocInSecurityIndex(mixed2TestRole, "meta", "test"); assertMigratedDocInSecurityIndex(upgradedTestRole, "meta", "test"); - // queries all roles by metadata - assertAllRoles(client(), "mixed1-test-role", "mixed2-test-role", "old-test-role", "upgraded-test-role"); + // query all roles by metadata - use assertBusy to handle the case where the node handling the query is not yet aware of the + // successful migration + assertBusy(() -> assertAllRoles(client(), "mixed1-test-role", "mixed2-test-role", "old-test-role", "upgraded-test-role")); } } @@ -184,7 +185,13 @@ private void assertAllRoles(RestClient client, String... roleNames) throws IOExc {"query":{"bool":{"must":[{"exists":{"field":"metadata.meta"}}]}},"sort":["name"]}"""; Request request = new Request(randomFrom("POST", "GET"), "/_security/_query/role"); request.setJsonEntity(metadataQuery); - Response response = client.performRequest(request); + Response response = null; + try { + response = client.performRequest(request); + } catch (ResponseException e) { + fail(e); + } + assertNotNull(response); assertOK(response); Map responseMap = responseAsMap(response); assertThat(responseMap.get("total"), is(roleNames.length));