diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index 145891c..c95a2d1 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -1,8 +1,11 @@ import subprocess from time import sleep +import shlex +import socket +from contextlib import suppress import requests -from environconfig import EnvironConfig, StringVar +from environconfig import EnvironConfig, StringVar, IntVar class Env(EnvironConfig): @@ -15,17 +18,31 @@ class Env(EnvironConfig): #: Where the Data API is KAPOW_DATAAPI_URL = StringVar(default="http://localhost:8080") + KAPOW_BOOT_TIMEOUT = IntVar(default=10) @given('I have a just started Kapow! server') @given('I have a running Kapow! server') def step_impl(context): context.server = subprocess.Popen( - Env.KAPOW_SERVER_CMD, + shlex.split(Env.KAPOW_SERVER_CMD), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, - shell=True) - is_running = context.server.poll() is None - assert is_running, "Server is not running!" + shell=False) + + # Check process is running with reachable APIs + open_ports = False + for _ in range(Env.KAPOW_BOOT_TIMEOUT): + is_running = context.server.poll() is None + assert is_running, "Server is not running!" + with suppress(requests.exceptions.ConnectionError): + open_ports = ( + requests.head(Env.KAPOW_CONTROLAPI_URL, timeout=1).status_code + and requests.head(Env.KAPOW_DATAAPI_URL, timeout=1).status_code) + if open_ports: + break + sleep(1) + + assert open_ports, "API is unreachable after KAPOW_BOOT_TIMEOUT" @when('I request a routes listing')