From 7e4b200f43f47eccafbd83455007a9e3bef2880a Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 14 Jul 2016 10:18:33 -0600 Subject: [PATCH] [TEST] ensure "index1" is yellow before searching in MigrateToolIT If the search runs before the primary shards are initialized for the "index1" index, the search may fail for unrelated reasons. Resolves elastic/elasticsearch#2818 Original commit: elastic/x-pack-elasticsearch@654ba9e1429558b0cf29396e74062a0a17979154 --- .../org/elasticsearch/xpack/security/MigrateToolIT.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/elasticsearch/qa/security-migrate-tests/src/test/java/org/elasticsearch/xpack/security/MigrateToolIT.java b/elasticsearch/qa/security-migrate-tests/src/test/java/org/elasticsearch/xpack/security/MigrateToolIT.java index 12cad15d5e6..00361ffefe2 100644 --- a/elasticsearch/qa/security-migrate-tests/src/test/java/org/elasticsearch/xpack/security/MigrateToolIT.java +++ b/elasticsearch/qa/security-migrate-tests/src/test/java/org/elasticsearch/xpack/security/MigrateToolIT.java @@ -118,6 +118,13 @@ public class MigrateToolIT extends MigrateToolTestCase { String token = basicAuthHeaderValue("bob", new SecuredString("changeme".toCharArray())); // Create "index1" index and try to search from it as "bob" client.filterWithHeader(Collections.singletonMap("Authorization", token)).admin().indices().prepareCreate("index1").get(); + // Wait for the index to be ready so it doesn't fail if no shards are initialized + client.admin().cluster().health(Requests.clusterHealthRequest("index1") + .timeout(TimeValue.timeValueSeconds(30)) + .waitForYellowStatus() + .waitForEvents(Priority.LANGUID) + .waitForRelocatingShards(0)) + .actionGet(); SearchResponse searchResp = client.filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("index1").get(); } }