Even when using existing server wait for yellow status before proceeding
This should solve travis issues where ES is run just before the test suite.
This commit is contained in:
@@ -29,13 +29,20 @@ CMD = """
|
|||||||
server = None
|
server = None
|
||||||
pidfile = tempfile.mktemp()
|
pidfile = tempfile.mktemp()
|
||||||
|
|
||||||
|
def get_client(**kwargs):
|
||||||
|
kw = {}
|
||||||
|
if 'TEST_ES_CONNECTION' in os.environ:
|
||||||
|
from elasticsearch import connection
|
||||||
|
kw['connection_class'] = getattr(connection, os.environ['TEST_ES_CONNECTION'])
|
||||||
|
kw.update(kwargs)
|
||||||
|
return Elasticsearch([os.environ['TEST_ES_SERVER']], **kw)
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
global server
|
global server
|
||||||
|
|
||||||
# use running ES instance, don't attempt to start our own
|
# if use running ES instance, don't attempt to start our own
|
||||||
if 'TEST_ES_SERVER' in os.environ:
|
if 'TEST_ES_SERVER' not in os.environ:
|
||||||
return
|
|
||||||
|
|
||||||
# check installed
|
# check installed
|
||||||
if subprocess.call('which elasticsearch >/dev/null 2>&1', shell=True) != 0:
|
if subprocess.call('which elasticsearch >/dev/null 2>&1', shell=True) != 0:
|
||||||
raise SkipTest("No Elasticsearch server, skipping integration tests.")
|
raise SkipTest("No Elasticsearch server, skipping integration tests.")
|
||||||
@@ -60,9 +67,10 @@ def setup():
|
|||||||
|
|
||||||
server = subprocess.Popen(cmd, shell=True)
|
server = subprocess.Popen(cmd, shell=True)
|
||||||
os.environ['TEST_ES_SERVER'] = 'localhost:%(port)s' % args
|
os.environ['TEST_ES_SERVER'] = 'localhost:%(port)s' % args
|
||||||
client = Elasticsearch([os.environ['TEST_ES_SERVER']])
|
|
||||||
|
|
||||||
# wait for green status
|
client = get_client()
|
||||||
|
|
||||||
|
# wait for yellow status
|
||||||
for _ in range(100):
|
for _ in range(100):
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
try:
|
try:
|
||||||
@@ -87,11 +95,7 @@ class ElasticTestCase(TestCase):
|
|||||||
client = None
|
client = None
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if ElasticTestCase.client is None:
|
if ElasticTestCase.client is None:
|
||||||
kw = {}
|
ElasticTestCase.client = get_client()
|
||||||
if 'TEST_ES_CONNECTION' in os.environ:
|
|
||||||
from elasticsearch import connection
|
|
||||||
kw['connection_class'] = getattr(connection, os.environ['TEST_ES_CONNECTION'])
|
|
||||||
ElasticTestCase.client = Elasticsearch([os.environ['TEST_ES_SERVER']], **kw)
|
|
||||||
self.client = ElasticTestCase.client
|
self.client = ElasticTestCase.client
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user