From 361d6bf89a72b21384a24f9f48ecdb3d06df3e5b Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Fri, 1 Mar 2013 23:36:13 +0100 Subject: [PATCH] spin a bit to wait for condition in test, so slow machines will still run it correctly --- .../local/LocalGatewayIndexStateTests.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/integration/gateway/local/LocalGatewayIndexStateTests.java b/src/test/java/org/elasticsearch/test/integration/gateway/local/LocalGatewayIndexStateTests.java index f8571bf5988..b0c0797b929 100644 --- a/src/test/java/org/elasticsearch/test/integration/gateway/local/LocalGatewayIndexStateTests.java +++ b/src/test/java/org/elasticsearch/test/integration/gateway/local/LocalGatewayIndexStateTests.java @@ -30,6 +30,7 @@ import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.gateway.Gateway; @@ -369,8 +370,13 @@ public class LocalGatewayIndexStateTests extends AbstractNodesTests { health = client("node1").admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); - // we need to wait for the allocate dangled to kick in - Thread.sleep(500); + // spin a bit waiting for the index to exists + long time = System.currentTimeMillis(); + while ((System.currentTimeMillis() - time) < TimeValue.timeValueSeconds(10).millis()) { + if (client("node1").admin().indices().prepareExists("test").execute().actionGet().isExists()) { + break; + } + } logger.info("--> verify that the dangling index exists"); assertThat(client("node1").admin().indices().prepareExists("test").execute().actionGet().isExists(), equalTo(true)); @@ -426,8 +432,13 @@ public class LocalGatewayIndexStateTests extends AbstractNodesTests { health = client("node1").admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); - // we need to wait for the allocate dangled to kick in - Thread.sleep(500); + // spin a bit waiting for the index to exists + long time = System.currentTimeMillis(); + while ((System.currentTimeMillis() - time) < TimeValue.timeValueSeconds(10).millis()) { + if (client("node1").admin().indices().prepareExists("test").execute().actionGet().isExists()) { + break; + } + } logger.info("--> verify that the dangling index exists"); assertThat(client("node1").admin().indices().prepareExists("test").execute().actionGet().isExists(), equalTo(true));