Check for reachable API in initial step.

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-08-20 10:29:58 +02:00
parent 7c5f127f22
commit 0a93135b4e
+22 -5
View File
@@ -1,8 +1,11 @@
import subprocess import subprocess
from time import sleep from time import sleep
import shlex
import socket
from contextlib import suppress
import requests import requests
from environconfig import EnvironConfig, StringVar from environconfig import EnvironConfig, StringVar, IntVar
class Env(EnvironConfig): class Env(EnvironConfig):
@@ -15,17 +18,31 @@ class Env(EnvironConfig):
#: Where the Data API is #: Where the Data API is
KAPOW_DATAAPI_URL = StringVar(default="http://localhost:8080") 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 just started Kapow! server')
@given('I have a running Kapow! server') @given('I have a running Kapow! server')
def step_impl(context): def step_impl(context):
context.server = subprocess.Popen( context.server = subprocess.Popen(
Env.KAPOW_SERVER_CMD, shlex.split(Env.KAPOW_SERVER_CMD),
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
shell=True) shell=False)
is_running = context.server.poll() is None
assert is_running, "Server is not running!" # 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') @when('I request a routes listing')