diff --git a/lib/common.py b/lib/common.py index 76022bf86..3959a41c6 100644 --- a/lib/common.py +++ b/lib/common.py @@ -205,8 +205,9 @@ def wait_for(fn: Callable[[], object], msg: str | None = None, timeout_secs: int return if time.perf_counter() - start_time >= timeout_secs: expected = 'True' if not invert else 'False' + suffix = ": " + msg if msg else "" raise TimeoutError( - "Timeout reached while waiting for fn call to yield %s (%s)." % (expected, timeout_secs) + "Timed out after %ss waiting for condition to be %s%s" % (timeout_secs, expected, suffix) ) time.sleep(retry_delay_secs) diff --git a/tests/system/test_systemd.py b/tests/system/test_systemd.py index bba6df6fa..af28e4db7 100644 --- a/tests/system/test_systemd.py +++ b/tests/system/test_systemd.py @@ -3,6 +3,7 @@ import logging import re +from lib.common import wait_for from lib.host import Host # Requirements: @@ -23,14 +24,20 @@ def test_failed_units(host: Host) -> None: pytest.fixture(scope='module') def test_verify_default_target(host: Host) -> None: - analyse = host.ssh('systemd-analyze verify default.target') - err = False - polkit_msg = "Cannot add dependency job for unit polkit.service, ignoring: Unit not found." - for line in analyse.splitlines(): - if line == polkit_msg: - pytest.xfail(f"drbd-reactor package must be fixed to remove dep to polkit: {polkit_msg}") - if line not in white_list_issues: - logging.error(f"{line}") - err = True - - assert not err + def analyse_default_target() -> bool: + # Look at what is using memory + # TODO: to remove + host.ssh('ps -eo pid,ppid,%mem,rss,args ww --sort=-rss | head -n 11') + host.ssh('free') + + analyse = host.ssh('systemd-analyze verify default.target') + polkit_msg = "Cannot add dependency job for unit polkit.service, ignoring: Unit not found." + for line in analyse.splitlines(): + if line == polkit_msg: + pytest.xfail(f"drbd-reactor package must be fixed to remove dep to polkit: {polkit_msg}") + if line not in white_list_issues: + logging.error(f"{line}") + return False + return True + + wait_for(analyse_default_target, "Wait for systemd-analyze verify default.target to be clean")