Commit df1e233c authored by Julien Muchembled's avatar Julien Muchembled

NEO: wait that the MySQL server is started before running tests

It already happened that the first tests of the suite failed
because the MySQL server was not fully started:

    OperationalError: (2002, 'Can\'t connect to local MySQL server through socket \'.../var/run/mariadb.sock\' (2 "No such file or directory")')
parent 603ef6df
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
""" """
import argparse, os, re, shutil, subprocess, sys, traceback import argparse, os, re, shutil, subprocess, sys, traceback
from erp5.util import taskdistribution from erp5.util import taskdistribution
from time import gmtime, strftime from time import gmtime, sleep, strftime, time
# pattern to get test counts from stdout # pattern to get test counts from stdout
SUMMARY_RE = re.compile( SUMMARY_RE = re.compile(
...@@ -82,7 +82,8 @@ def main(): ...@@ -82,7 +82,8 @@ def main():
if not test_result_line: if not test_result_line:
break break
temp = os.path.join(TEMP_DIRECTORY, 'tests-' + test_result_line.name) adapter = test_result_line.name
temp = os.path.join(TEMP_DIRECTORY, 'tests-' + adapter)
if os.path.exists(temp): if os.path.exists(temp):
shutil.rmtree(temp) shutil.rmtree(temp)
os.mkdir(temp) os.mkdir(temp)
...@@ -90,46 +91,47 @@ def main(): ...@@ -90,46 +91,47 @@ def main():
args = [RUN_NEO_TESTS_COMMAND, '-ufz'] args = [RUN_NEO_TESTS_COMMAND, '-ufz']
command = ' '.join(args) command = ' '.join(args)
env = {'TEMP': temp, env = {'TEMP': temp,
'NEO_TESTS_ADAPTER': test_result_line.name, 'NEO_TESTS_ADAPTER': adapter,
'NEO_TEST_ZODB_FUNCTIONAL': '1', 'NEO_TEST_ZODB_FUNCTIONAL': '1',
'NEO_DB_USER': 'root', 'NEO_DB_USER': 'root'}
'NEO_DB_SOCKET': NEO_DB_SOCKET}
try: try:
if adapter == 'MySQL':
env['NEO_DB_SOCKET'] = NEO_DB_SOCKET
timeout = time() + 60
while not os.path.exists(NEO_DB_SOCKET):
if timeout < time():
raise RuntimeError("MySQL server not started")
sleep(1)
with open(os.devnull) as stdin: with open(os.devnull) as stdin:
p = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE, p = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env) stderr=subprocess.PIPE, env=env)
except Exception: except Exception:
# Catch any exception here, to warn user instead of being silent, end = time()
# by generating fake error result stderr = traceback.format_exc()
result = dict(status_code=-1, status_dict = {}
command=command, else:
stderr=traceback.format_exc(),
stdout='')
# XXX: inform test node master of error
raise EnvironmentError(result)
# parse test stdout / stderr, hint to speed up use files first!
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
date = strftime("%Y/%m/%d %H:%M:%S", gmtime()) end = time()
test_count, unexpected_count, expected_count, skip_count, duration = \ test_count, unexpected_count, expected_count, skip_count, duration = \
parseTestStdOut(stdout) parseTestStdOut(stdout)
status_dict = dict(
test_count = test_count,
error_count = unexpected_count, # XXX
failure_count = expected_count, # XXX
skip_count = skip_count,
stdout= stdout)
# print to stdout so we can see in testnode logs # print to stdout so we can see in testnode logs
sys.stdout.write(stdout) sys.stdout.write(stdout)
sys.stderr.write(stderr) sys.stderr.write(stderr)
# report status back to Nexedi ERP5 # report status back to Nexedi ERP5
test_result_line.stop( test_result_line.stop(
test_count = test_count,
error_count = unexpected_count, # XXX
failure_count = expected_count, # XXX
skip_count = skip_count,
duration = duration,
date = date,
command = command, command = command,
stdout= stdout, date = strftime("%Y/%m/%d %H:%M:%S", gmtime(end)),
stderr= stderr, stderr=stderr,
html_test_result='') **status_dict)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
...@@ -26,7 +26,7 @@ md5sum = ee8401a4e7d82bf488a57e3399f9ce48 ...@@ -26,7 +26,7 @@ md5sum = ee8401a4e7d82bf488a57e3399f9ce48
[runTestSuite.in] [runTestSuite.in]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_buildout_section_name_} url = ${:_profile_base_location_}/${:_buildout_section_name_}
md5sum = 050593aef62fd4aa241d8ad378111c36 md5sum = c5599e0086f85999e222a3bef627f93b
[runTestSuite_py] [runTestSuite_py]
recipe = zc.recipe.egg recipe = zc.recipe.egg
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment