Skip to content

Commit dc351b9

Browse files
committed
Fix testRoleMigration race condition (elastic#138742)
1 parent e7bfe2d commit dc351b9

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
@@ -54,8 +54,9 @@ public void testRoleMigration() throws Exception {
5454
assertMigratedDocInSecurityIndex(mixed1TestRole, "meta", "test");
5555
assertMigratedDocInSecurityIndex(mixed2TestRole, "meta", "test");
5656
assertMigratedDocInSecurityIndex(upgradedTestRole, "meta", "test");
57-
// queries all roles by metadata
58-
assertAllRoles(client(), "mixed1-test-role", "mixed2-test-role", "old-test-role", "upgraded-test-role");
57+
// query all roles by metadata - use assertBusy to handle the case where the node handling the query is not yet aware of the
58+
// successful migration
59+
assertBusy(() -> assertAllRoles(client(), "mixed1-test-role", "mixed2-test-role", "old-test-role", "upgraded-test-role"));
5960
}
6061
}
6162

@@ -175,7 +176,13 @@ private void assertAllRoles(RestClient client, String... roleNames) throws IOExc
175176
{"query":{"bool":{"must":[{"exists":{"field":"metadata.meta"}}]}},"sort":["name"]}""";
176177
Request request = new Request(randomFrom("POST", "GET"), "/_security/_query/role");
177178
request.setJsonEntity(metadataQuery);
178-
Response response = client.performRequest(request);
179+
Response response = null;
180+
try {
181+
response = client.performRequest(request);
182+
} catch (ResponseException e) {
183+
fail(e);
184+
}
185+
assertNotNull(response);
179186
assertOK(response);
180187
Map<String, Object> responseMap = responseAsMap(response);
181188
assertThat(responseMap.get("total"), is(roleNames.length));

0 commit comments

Comments
 (0)