diff --git a/tests/python/core/cloudxr/test_background.py b/tests/python/core/cloudxr/test_background.py index 07d1d5dcf0..6f94a0c687 100644 --- a/tests/python/core/cloudxr/test_background.py +++ b/tests/python/core/cloudxr/test_background.py @@ -58,7 +58,15 @@ def test_recognises_a_service_under_any_shipped_module_name(self, tmp_path, modu ) try: background.pid_path(str(tmp_path)).write_text(f"{proc.pid}\n") - assert background.read_pid(str(tmp_path)) == proc.pid + # A freshly spawned pid's /proc//cmdline isn't guaranteed to be + # populated the instant Popen() returns, especially on a loaded CI + # runner - poll briefly instead of asserting on the very first read. + deadline = time.monotonic() + 2.0 + pid = background.read_pid(str(tmp_path)) + while pid is None and time.monotonic() < deadline: + time.sleep(0.05) + pid = background.read_pid(str(tmp_path)) + assert pid == proc.pid finally: proc.kill() proc.wait()