Fix race in ClusterStatsIT

ClusterStatsIT#testClusterStatus() contained a race where the
test cluster might still be initializing while test already checks
for a green health status.

With this commit the test waits until the cluster status changed and
checks health afterwards.

Checked with @bleskes.
This commit is contained in:
Daniel Mitterdorfer 2015-11-17 13:21:40 +01:00
parent 1201843d72
commit 2522645123
1 changed files with 3 additions and 1 deletions

View File

@ -171,7 +171,7 @@ public class ClusterStatsIT extends ESIntegTestCase {
assertThat(response.getNodesStats().getOs().getAllocatedProcessors(), equalTo(7)); assertThat(response.getNodesStats().getOs().getAllocatedProcessors(), equalTo(7));
} }
public void testClusterStatus() throws Exception { public void testClusterStatusWhenStateNotRecovered() throws Exception {
// stop all other nodes // stop all other nodes
internalCluster().ensureAtMostNumDataNodes(0); internalCluster().ensureAtMostNumDataNodes(0);
@ -180,6 +180,8 @@ public class ClusterStatsIT extends ESIntegTestCase {
assertThat(response.getStatus(), equalTo(ClusterHealthStatus.RED)); assertThat(response.getStatus(), equalTo(ClusterHealthStatus.RED));
internalCluster().ensureAtLeastNumDataNodes(3); internalCluster().ensureAtLeastNumDataNodes(3);
// wait for the cluster status to settle
ensureGreen();
response = client().admin().cluster().prepareClusterStats().get(); response = client().admin().cluster().prepareClusterStats().get();
assertThat(response.getStatus(), equalTo(ClusterHealthStatus.GREEN)); assertThat(response.getStatus(), equalTo(ClusterHealthStatus.GREEN));
} }