Skip to content

Commit 488184a

Browse files
committed
Fix testRoleMigration race condition (elastic#138742)
1 parent 9b3083e commit 488184a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/SecurityIndexRolesMetadataMigrationIT.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ public void testRoleMigration() throws Exception {
6363
assertMigratedDocInSecurityIndex(mixed1TestRole, "meta", "test");
6464
assertMigratedDocInSecurityIndex(mixed2TestRole, "meta", "test");
6565
assertMigratedDocInSecurityIndex(upgradedTestRole, "meta", "test");
66-
// queries all roles by metadata
67-
assertAllRoles(client(), "mixed1-test-role", "mixed2-test-role", "old-test-role", "upgraded-test-role");
66+
// query all roles by metadata - use assertBusy to handle the case where the node handling the query is not yet aware of the
67+
// successful migration
68+
assertBusy(() -> assertAllRoles(client(), "mixed1-test-role", "mixed2-test-role", "old-test-role", "upgraded-test-role"));
6869
}
6970
}
7071

@@ -184,7 +185,13 @@ private void assertAllRoles(RestClient client, String... roleNames) throws IOExc
184185
{"query":{"bool":{"must":[{"exists":{"field":"metadata.meta"}}]}},"sort":["name"]}""";
185186
Request request = new Request(randomFrom("POST", "GET"), "/_security/_query/role");
186187
request.setJsonEntity(metadataQuery);
187-
Response response = client.performRequest(request);
188+
Response response = null;
189+
try {
190+
response = client.performRequest(request);
191+
} catch (ResponseException e) {
192+
fail(e);
193+
}
194+
assertNotNull(response);
188195
assertOK(response);
189196
Map<String, Object> responseMap = responseAsMap(response);
190197
assertThat(responseMap.get("total"), is(roleNames.length));

0 commit comments

Comments
 (0)