From 7f36a227f764a6f2b88350b81c9776625884c344 Mon Sep 17 00:00:00 2001 From: Gareth Morgan Date: Wed, 7 Oct 2026 17:40:09 -0400 Subject: [PATCH] test(cloudxr): fix flaky cmdline-read race in test_background.py test_recognises_a_service_under_any_shipped_module_name intermittently failed with "assert None == " - background.read_pid() reads /proc//cmdline right after Popen() returns, but on a loaded CI runner (e.g. parallel ctest matrix jobs) the child's /proc entry isn't always populated by then. Poll briefly instead of asserting on the first read. Confirmed pre-existing on main (reproduced the same way on commit 6960d4a59, unrelated to any in-flight PR); ran the fixed test 5x with no failures. Co-Authored-By: Claude Sonnet 5 Signed-off-by: Gareth Morgan --- tests/python/core/cloudxr/test_background.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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()