From f1dd38b9db61015f5af38a189c9c3e0da59268ac Mon Sep 17 00:00:00 2001 From: WouldYouKindly Date: Mon, 17 Jan 2022 15:54:24 +0300 Subject: [PATCH] Fix readiness check --- pytest_hoverfly/base.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pytest_hoverfly/base.py b/pytest_hoverfly/base.py index 51daf07..c628f46 100644 --- a/pytest_hoverfly/base.py +++ b/pytest_hoverfly/base.py @@ -2,6 +2,7 @@ import dataclasses as dc import os +import socket import time import typing as t import urllib.error @@ -50,12 +51,23 @@ def try_from_env(cls, env: t.Mapping[str, str]) -> t.Optional[Hoverfly]: return Hoverfly(hoverfly_host, int(admin_port), int(proxy_port)) def is_ready(self) -> bool: + return self.admin_endpoint_is_ready() and self.proxy_is_ready() + + def admin_endpoint_is_ready(self): try: urllib.request.urlopen(f"{self.admin_endpoint}/state") return True except (urllib.error.URLError, RemoteDisconnected): return False + def proxy_is_ready(self): + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((self.host, self.proxy_port)) + return True + except ConnectionRefusedError: + return False + def get_container( container_name: t.Optional[str] = None,