Allow get_test_client to not wait for es cluster startup

This commit is contained in:
Honza Král
2014-05-20 15:05:40 +02:00
parent 4849fbedb2
commit b1d36926c1
+3 -4
View File
@@ -9,7 +9,7 @@ except ImportError:
from elasticsearch import Elasticsearch from elasticsearch import Elasticsearch
from elasticsearch.exceptions import ConnectionError from elasticsearch.exceptions import ConnectionError
def get_test_client(): def get_test_client(nowait=False):
# construct kwargs from the environment # construct kwargs from the environment
kw = {} kw = {}
if 'TEST_ES_CONNECTION' in os.environ: if 'TEST_ES_CONNECTION' in os.environ:
@@ -19,13 +19,12 @@ def get_test_client():
client = Elasticsearch([os.environ.get('TEST_ES_SERVER', {})], **kw) client = Elasticsearch([os.environ.get('TEST_ES_SERVER', {})], **kw)
# wait for yellow status # wait for yellow status
for _ in range(100): for _ in range(1 if nowait else 100):
time.sleep(.1)
try: try:
client.cluster.health(wait_for_status='yellow') client.cluster.health(wait_for_status='yellow')
return client return client
except ConnectionError: except ConnectionError:
continue time.sleep(.1)
else: else:
# timeout # timeout
raise SkipTest("Elasticsearch failed to start.") raise SkipTest("Elasticsearch failed to start.")