From 6134eb0293d7b4796ce14b41f63e94d72da9756b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 21 Mar 2025 12:41:27 +0100 Subject: [PATCH] tests/sshd: add a 5 second timeout for sshd to start --- pkgs/clan-cli/tests/sshd.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/tests/sshd.py b/pkgs/clan-cli/tests/sshd.py index 1b9281a34..82c9c1251 100644 --- a/pkgs/clan-cli/tests/sshd.py +++ b/pkgs/clan-cli/tests/sshd.py @@ -10,13 +10,16 @@ from tempfile import TemporaryDirectory from typing import TYPE_CHECKING import pytest -from fixture_error import FixtureError if TYPE_CHECKING: from command import Command from ports import PortFunction +class SshdError(Exception): + pass + + class Sshd: def __init__(self, port: int, proc: subprocess.Popen[str], key: str) -> None: self.port = port @@ -135,6 +138,10 @@ def sshd( extra_env=env, ) monkeypatch.delenv("SSH_AUTH_SOCK", raising=False) + + timeout = 5 + start_time = time.time() + while True: print(sshd_config.path) if ( @@ -162,5 +169,8 @@ def sshd( rc = proc.poll() if rc is not None: 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)