feat(driver): wait for Squish server port to listen
Doing silly retries is just not reliable, this is. Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
fc665cf5ec
commit
eec2e382d8
|
@ -3,6 +3,7 @@ import typing
|
|||
|
||||
import configs.testpath
|
||||
from scripts.utils import local_system
|
||||
from scripts.utils.wait_for_port import wait_for_port
|
||||
|
||||
_PROCESS_NAME = '_squishserver'
|
||||
|
||||
|
@ -40,6 +41,12 @@ class SquishServer:
|
|||
cls.pid = None
|
||||
cls.port = None
|
||||
|
||||
@classmethod
|
||||
def wait(cls, timeout: int = 1, retries: int = 10):
|
||||
LOG.info('Waiting for Squish server port %s:%d...', cls.host, cls.port)
|
||||
wait_for_port(cls.host, cls.port, timeout, retries)
|
||||
LOG.info('Squish server port available!')
|
||||
|
||||
# https://doc-snapshots.qt.io/squish/cli-squishserver.html
|
||||
@classmethod
|
||||
def configuring(cls, action: str, options: typing.Union[int, str, list]):
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import time
|
||||
import socket
|
||||
import logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
def wait_for_port(host: str, port: int, timeout: int = 1, retries: int = 0):
|
||||
for i in range(retries+1):
|
||||
try:
|
||||
LOG.debug('Checking TCP port: %s:%d', host, port)
|
||||
with socket.create_connection((host, port), timeout=timeout):
|
||||
return
|
||||
except OSError as err:
|
||||
LOG.debug('Connection error: %s', err)
|
||||
time.sleep(1)
|
||||
continue
|
||||
|
||||
LOG.debug('Timed out waiting for TCP port: %s:%d', host, port)
|
||||
raise TimeoutError(
|
||||
'Unable to establish TCP connection with %s:%s.' % (host, port)
|
||||
)
|
Loading…
Reference in New Issue