diff --git a/tools/test-run-dev b/tools/test-run-dev new file mode 100755 index 0000000000..9f9e2a9681 --- /dev/null +++ b/tools/test-run-dev @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +from __future__ import print_function +from __future__ import absolute_import + +import os +import sys +import time +import signal +import subprocess + +from six.moves import range + + +TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +def start_server(logfile): + failure = True + key = "Quit the server with CTRL-C." + for i in range(200): + time.sleep(0.5) + print("Polling run-dev...") + logfile.seek(0) + if key in logfile.read(): + failure = False + break + + return failure + + +def test_nagios(nagios_logfile): + ZULIP_DIR = os.path.join(TOOLS_DIR, '..') + API_DIR = os.path.join(ZULIP_DIR, 'api') + os.chdir(API_DIR) + subprocess.call(['python', 'setup.py', 'install']) + PUPPET_DIR = os.path.join(ZULIP_DIR, 'puppet') + os.chdir(ZULIP_DIR) + my_env = os.environ.copy() + my_env['PYTHONPATH'] = ZULIP_DIR + args = [ + os.path.join(PUPPET_DIR, + 'zulip/files/nagios_plugins/zulip_app_frontend/check_send_receive_time'), + '--nagios', + '--site=127.0.0.1:9991', + ] + result = subprocess.check_output(args, env=my_env, + stderr=nagios_logfile) + + if 'success' in result: + return True + + return False + + +def close_and_get_content(file_handle): + file_handle.seek(0) + content = file_handle.read() + file_handle.close() + return content + + +if __name__ == '__main__': + print("Testing development server start!") + + logfile = open('/tmp/run-dev-output', 'w+') + nagios_logfile = open('/tmp/test-nagios-output', 'w+') + + args = ["{}/run-dev.py".format(TOOLS_DIR)] + run_dev = subprocess.Popen(args, stdout=logfile, stderr=logfile) + + try: + failure = start_server(logfile) + failure = failure or not test_nagios(nagios_logfile) + finally: + logfile = close_and_get_content(logfile) + nagios_logfile = close_and_get_content(nagios_logfile) + + run_dev.send_signal(signal.SIGINT) + run_dev.wait() + + if not failure and 'Traceback' in logfile + ' ' + nagios_logfile: + failure = True + + if failure: + print("Development server is not working properly:") + print(logfile) + print("check_send_receive_time output:") + print(nagios_logfile) + sys.exit(1) + else: + print("Development server is working properly.") + sys.exit(0) diff --git a/tools/travis/backend b/tools/travis/backend index 5d0995bb3c..19a9da4d29 100755 --- a/tools/travis/backend +++ b/tools/travis/backend @@ -7,3 +7,4 @@ export PATH=$PATH:/srv/zulip-venv/bin ./tools/test-backend ./tools/test-management ./tools/test-migrations +./tools/test-run-dev