ab-retail: the close is asked of every browser parent of the profile (the launcher has no window)

This commit is contained in:
feder-cr committed 2026-12-02 13:32:47 +01:00
1 parent a7f57ac4f0
commit 40841aa857
2 files changed
+15 -6

No files matched your search

+14 -6
View File
@@ -72,8 +72,9 @@ def sha256_file(path) -> str:
# -
# The launch.
def browser_parent_of(profile: Path, processes=None) -> int | None:
"""The pid of the browser parent that was started with `-profile <profile>`: a `firefox.exe` without `-contentproc` whose command line names the profile. None when there is none (yet)."""
def browser_parents_of(profile: Path, processes=None) -> list:
"""The pids, oldest first, of the browser parents that were started with `-profile <profile>`: a `firefox.exe` without `-contentproc` whose command line names the profile. On
Windows there are two: the launcher process the command started, and the browser it starts and waits for (run 46880238752: the oldest one has no window). Empty when none (yet)."""
if processes is None:
import psutil
@@ -88,7 +89,13 @@ def browser_parent_of(profile: Path, processes=None) -> int | None:
found.append((p.create_time(), p.pid))
except Exception: # noqa: BLE001 - a process that is gone
continue
return min(found)[1] if found else None
return [pid for _born, pid in sorted(found)]
def browser_parent_of(profile: Path, processes=None) -> int | None:
"""The oldest of `browser_parents_of`, None when there is none (yet)."""
found = browser_parents_of(profile, processes)
return found[0] if found else None
def close_windows_of(pid: int) -> int:
@@ -159,10 +166,11 @@ def run_retail_seed(binary: str, index: int, work: Path, name: str, audit_dir=No
else:
time.sleep(HOLD_AFTER_PAGE_S)
started = time.monotonic()
asked = close_windows_of(parent) if parent is not None else 0
parents = browser_parents_of(profile)
asked = sum(close_windows_of(pid) for pid in parents)
if parent is not None and not asked:
problems.append("the browser parent %d had no visible window to close" % parent)
ended = wait_for(lambda: not psutil.pid_exists(parent), CLOSE_LIMIT_S) if parent is not None else True
problems.append("no browser parent of %s (%s) had a visible window to close" % (profile, ", ".join(str(p) for p in parents) or "none"))
ended = wait_for(lambda: not any(psutil.pid_exists(pid) for pid in parents), CLOSE_LIMIT_S) if parent is not None else True
if not ended:
problems.append("the browser did not end %d s after WM_CLOSE: it was ended by the oracle" % CLOSE_LIMIT_S)
close = {"windows_asked": asked, "close_s": round(time.monotonic() - started, 2), "ended_by_itself": bool(ended)}
+1
View File
@@ -4042,6 +4042,7 @@ def test_the_browser_parent_is_the_oldest_firefox_without_contentproc_that_names
P("firefox.exe", ["firefox.exe", "-profile", str(profile)], 5, 12), P("firefox.exe", ["firefox.exe", "-profile", str(profile)], 4, 13),
P("python.exe", ["python.exe", str(profile)], 0, 14)]
assert retail.browser_parent_of(profile, processes) == 13
assert retail.browser_parents_of(profile, processes) == [13, 12], "the launcher and the browser it starts: the window is the younger one's, so the close is asked of both"
assert retail.browser_parent_of(profile, processes[:2]) is None