tests/sshd: add a 5 second timeout for sshd to start
This commit is contained in:
@@ -10,13 +10,16 @@ from tempfile import TemporaryDirectory
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from fixture_error import FixtureError
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from command import Command
|
from command import Command
|
||||||
from ports import PortFunction
|
from ports import PortFunction
|
||||||
|
|
||||||
|
|
||||||
|
class SshdError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Sshd:
|
class Sshd:
|
||||||
def __init__(self, port: int, proc: subprocess.Popen[str], key: str) -> None:
|
def __init__(self, port: int, proc: subprocess.Popen[str], key: str) -> None:
|
||||||
self.port = port
|
self.port = port
|
||||||
@@ -135,6 +138,10 @@ def sshd(
|
|||||||
extra_env=env,
|
extra_env=env,
|
||||||
)
|
)
|
||||||
monkeypatch.delenv("SSH_AUTH_SOCK", raising=False)
|
monkeypatch.delenv("SSH_AUTH_SOCK", raising=False)
|
||||||
|
|
||||||
|
timeout = 5
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print(sshd_config.path)
|
print(sshd_config.path)
|
||||||
if (
|
if (
|
||||||
@@ -162,5 +169,8 @@ def sshd(
|
|||||||
rc = proc.poll()
|
rc = proc.poll()
|
||||||
if rc is not None:
|
if rc is not None:
|
||||||
msg = f"sshd processes was terminated with {rc}"
|
msg = f"sshd processes was terminated with {rc}"
|
||||||
raise FixtureError(msg)
|
raise SshdError(msg)
|
||||||
|
if time.time() - start_time > timeout:
|
||||||
|
msg = "Timeout while waiting for sshd to be ready"
|
||||||
|
raise SshdError(msg)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|||||||
Reference in New Issue
Block a user