Added real test server
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import time
|
||||
import subprocess
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
from nose import SkipTest
|
||||
|
||||
data_dir = None
|
||||
|
||||
CMD = """
|
||||
elasticsearch \
|
||||
-f \
|
||||
-D es.cluster.name=%(cluster_name)s \
|
||||
-D es.node.name=test_name \
|
||||
-D es.http.port=%(port)s \
|
||||
-D es.gateway.type=none \
|
||||
-D es.index.store.type=memory \
|
||||
-D es.discovery.zen.ping.multicast.enabled=false \
|
||||
-D es.path.data=%(data_dir)s \
|
||||
-D es.pidfile=%(pidfile)s \
|
||||
>/dev/null 2>&1
|
||||
"""
|
||||
|
||||
server = None
|
||||
pidfile = tempfile.mktemp()
|
||||
|
||||
def setup():
|
||||
global server
|
||||
|
||||
# check installed
|
||||
if subprocess.call('which vim >/dev/null 2>&1', shell=True) != 0:
|
||||
raise SkipTest("No Elasticsearch server, skipping integration tests.")
|
||||
|
||||
args = {
|
||||
'cluster_name': 'es_client_test',
|
||||
'port': 9900,
|
||||
'data_dir': tempfile.tempdir,
|
||||
'pidfile': pidfile
|
||||
}
|
||||
|
||||
# check running
|
||||
try:
|
||||
requests.get('http://localhost:%(port)s' % args)
|
||||
except requests.ConnectionError:
|
||||
pass
|
||||
else:
|
||||
raise SkipTest('Elasticsearch already running!')
|
||||
|
||||
|
||||
cmd = CMD % args
|
||||
|
||||
server = subprocess.Popen(cmd, shell=True)
|
||||
|
||||
# wait for green status
|
||||
for _ in range(100):
|
||||
response = None
|
||||
time.sleep(.1)
|
||||
try:
|
||||
response = requests.get('http://localhost:%(port)s/_cluster/health' % args)
|
||||
except requests.ConnectionError:
|
||||
pass
|
||||
|
||||
if response and response.json()['status'] == 'green':
|
||||
break
|
||||
|
||||
else:
|
||||
# timeout
|
||||
raise SkipTest("Elasticsearch failed to start.")
|
||||
|
||||
|
||||
def teardown():
|
||||
if server is not None:
|
||||
with open(pidfile) as pidf:
|
||||
pid = pidf.read()
|
||||
os.kill(int(pid), 15)
|
||||
server.wait()
|
||||
Reference in New Issue
Block a user