Skip to content

Commit

Permalink
Fix readiness check
Browse files Browse the repository at this point in the history
  • Loading branch information
WouldYouKindly committed Jan 17, 2022
1 parent ff5465e commit f1dd38b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pytest_hoverfly/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses as dc
import os
import socket
import time
import typing as t
import urllib.error
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f1dd38b

Please sign in to comment.