fix flakey tests

This commit is contained in:
Qyriad 2026-03-26 12:44:48 +01:00
parent 513627a677
commit ef1a6054ee
3 changed files with 49 additions and 23 deletions

View file

@ -49,6 +49,19 @@ parser.add_argument("--log-level", type=str)
#parser.add_argument("--stats", action="store_true")
#parser.add_argument("--stats-port", type=int)
@beartype
def parse_systemd_exec(prop: str) -> str:
# idk why, but systemd exec lines are secretly DBus dictionaries,
# which `systemctl show -p` represents as an equals-delimited, semicolon-separated,
# key-value pair, all in curly braces. e.g.:
# { path=/nix/store/… ; argv[]=foobar ; ignore_errors=no ; … }
inside = prop.removeprefix('{ ').removesuffix(' }')
pairs = inside.split(';')
# FIXME: don't assume `path` is the first one.
# In case systemd ever changes that.
_key, path = pairs[0].split('=')
return path.strip()
@beartype
def get_cli_args() -> argparse.Namespace:
machine.wait_for_unit("distccd.service")
@ -56,15 +69,10 @@ def get_cli_args() -> argparse.Namespace:
machine.log(f"{mainpid=}")
pidtext = machine.succeed(f"pgrep -P {mainpid}")
machine.log(f"{pidtext=}")
pid = int(pidtext.splitlines()[0])
machine.log(f"{pid=}")
execstart = machine.get_unit_property("distccd.service", "ExecStart")
print(f"{execstart=}")
cmdline = machine.succeed(f"cat /proc/{pid}/cmdline")
cmdline_args = cmdline.split("\0")
pid = int(pidtext.splitlines()[0])
cmdline_args = machine.succeed(rf"cat /proc/{pid}/cmdline | tr '\0' '\n'").splitlines()
machine.log(f"{cmdline_args=}")
print(f"{cmdline_args=}")
args, rest = parser.parse_known_args(cmdline_args)
return args
@ -106,6 +114,11 @@ def run_all_tests(machine: Machine, *, use_daemon: bool):
dynix_out = machine.succeed("dynix --version")
assert "dynix" in dynix_out, f"dynix not in {dynix_out=}"
machine.succeed("systemctl start user@0.service")
machine.wait_for_unit("user@0.service")
machine.succeed("systemctl start dynix-daemon.service")
machine.wait_for_unit("dynix-daemon.service")
# Config should have our initial values.
args = get_cli_args()
assert args.jobs == 12, f'{args.jobs=} != 12'
@ -158,10 +171,6 @@ machine.reboot()
machine.wait_for_unit("default.target")
machine.wait_for_unit("install-dynix.service")
machine.succeed("systemctl start user@0.service")
machine.wait_for_unit("user@0.service")
machine.succeed("systemctl start dynix-daemon.service")
machine.wait_for_unit("dynix-daemon.service")
try:
run_all_tests(machine, use_daemon=True)
except Exception as e: