def all_services_running(): """Check that all webservices were started successfully. All webservices controlled by `supervisor` must be currently running (RUNNING) or have finished successfully (EXITED). Returns `False` if any other statuses (STARTING, STOPPED, etc.) are present. """ return all(['RUNNING' in line or 'EXITED' in line for line in supervisor_status()])
def all_services_running(): """Check that all webservices were started successfully. All webservices controlled by `supervisor` must be currently running (RUNNING) or have finished successfully (EXITED). Returns `False` if any other statuses (STARTING, STOPPED, etc.) are present. """ valid_states = ('RUNNING', 'EXITED') supervisor_output, return_code = supervisor_status() running = all([any(state in line for state in valid_states) for line in supervisor_output]) # Return 3 is associated with a service exiting normally return running if return_code in (0, 3) else False
def verify_server_availability(url, timeout=60): """Raise exception if webservices fail to launch or connection to `url` is not available. """ for i in range(timeout): try: assert all_services_running(), ("Webservice(s) failed to launch:\n" + '\n'.join(supervisor_status())) response = requests.get(url) assert response.status_code == 200, ("Expected status 200, got" f" {response.status_code}" f" for URL {url}.") response = requests.get(url + '/static/build/bundle.js') assert response.status_code == 200, ("Javascript bundle not found," " did Webpack fail?") return # all checks passed except Exception as e: if i == max(range(timeout)): # last iteration raise ConnectionError(str(e)) from None time.sleep(1)
def verify_server_availability(url, timeout=180): """Raise exception if webservices fail to launch or connection to `url` is not available. """ for i in range(timeout): if not os.path.exists("baselayer/conf/supervisor/supervisor.conf"): time.sleep(1) continue try: statuses, errcode = supervisor_status() assert (all_services_running( )), "Webservice(s) failed to launch:\n" + "\n".join(statuses) response = requests.get(url) assert response.status_code == 200, ("Expected status 200, got" f" {response.status_code}" f" for URL {url}.") response = requests.get(url + "/static/build/main.bundle.js") assert response.status_code == 200, ("Javascript bundle not found," " did Webpack fail?") return # all checks passed except Exception as e: if i == timeout - 1: # last iteration raise ConnectionError(str(e)) from None time.sleep(1)
from survey_app.app_server import load_config basedir = pathlib.Path(os.path.dirname(__file__))/'..' cfg = load_config([basedir/'config.yaml.example', basedir/TEST_CONFIG]) init_db(**cfg['database']) clear_tables() web_client = subprocess.Popen(['make', 'testrun'], cwd=base_dir) print('[test_frontend] Waiting for supervisord to launch all server processes...') try: timeout = 0 while ((timeout < 30) and (not all([b'RUNNING' in line for line in supervisor_status()]))): time.sleep(1) timeout += 1 if timeout == 10: print('[test_frontend] Could not launch server processes; terminating') sys.exit(-1) for timeout in range(10): conn = http.HTTPConnection("localhost", 7000) try: conn.request('HEAD', '/') status = conn.getresponse().status if status == 200: break except socket.error:
cfg = load_config([basedir / 'config.yaml', basedir / TEST_CONFIG]) init_db(**cfg['database']) clear_tables() web_client = subprocess.Popen(['make', 'testrun'], cwd=base_dir) print( '[test_frontend] Waiting for supervisord to launch all server processes...' ) try: timeout = 0 while ((timeout < 30) and (not all([b'RUNNING' in line for line in supervisor_status()]))): time.sleep(1) timeout += 1 if timeout == 10: print( '[test_frontend] Could not launch server processes; terminating' ) sys.exit(-1) for timeout in range(10): conn = http.HTTPConnection("localhost", 5000) try: conn.request('HEAD', '/') status = conn.getresponse().status if status == 200: