tests: the Fission bench counts the processes that host a site, not every new content process

test_same_site_other_port_stays_in_process was red on the e2e of the 0.50.0 commit ("a same-site frame
started a process: [13443]"): the bench counted every `-contentproc ... tab` pid, and the engine starts a
preallocated content process to refill its pool whenever it gets to it. On Linux the engine names a content
process by its remote type (ContentChild::SetProcessName, prctl PR_SET_NAME): "Isolated Web Co" once it
hosts a site of strategy 1, "Web Content" while preallocated. Measured on firefox-62: a cross-site frame
renames a preallocated process and a new "Web Content" refills the pool; a same-site frame changes neither.
The two tests that count processes skip off Linux, where no process carries a name.

Unit test with the measured processes: 3 red on the old bench, 3 green here. e2e on firefox-62 (candidate
#6, Linux): the bench file 17 passed; the two counting tests 15 of 15 runs green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
feder-crandClaude Opus 5.5 committed 2026-11-11 13:18:54 +01:00
1 parent 82d88c848f
commit 5402da4d80
2 files changed
+94 -16

No files matched your search

+37 -16
View File
@@ -21,14 +21,20 @@ test says what the product does not do yet and the step that makes it green:
9 named world after the OOP frame step 1a + 2b
10 console of the OOP frame step 1a
The oracle for "another process" is the engine's own processes below the test (`-contentproc ... tab`): a
cross-site frame adds at least one, a same-site one adds none. The count is read after the browser is quiet
(the engine pre-allocates a content process and replaces it when it is used).
The oracle for "another process" is the set of the engine's processes that host a site, below the test: a
cross-site frame adds at least one, a same-site one adds none. A content process is not one of them by being
new: the engine keeps preallocated content processes (`dom.ipc.processPrelaunch.fission.number`), hands one to
a site when a site needs a process, and starts another to refill the pool, whenever it gets to it. A pid that
appears is often that refill, not a site. On Linux the process says which it is: `ContentChild::SetProcessName`
names it by its remote type with `prctl(PR_SET_NAME)` (ipc/glue/ProcessUtils_linux.cpp), "Isolated Web Co" for
a site of strategy 1 (`webIsolated=<site>`), "Web Content" while it is preallocated. Windows names no process
(ProcessUtils_none.cpp), so the two tests that count processes skip there. The set is read once it is quiet.
"""
from __future__ import annotations
import json
import os
import sys
import threading
import time
from http.server import BaseHTTPRequestHandler
@@ -125,30 +131,44 @@ def engine_dir(firefox_binary):
return str(Path(firefox_binary).resolve().parent)
def content_processes(engine_dir):
"""The pids of the engine's web content processes (`-contentproc ... tab`) below this test."""
#: The name a content process of strategy 1 takes once it hosts a site (15 characters: PR_SET_NAME keeps 15 of
#: "Isolated Web Content"). A preallocated one is "Web Content" until a site is given to it.
SITE_PROCESS_NAME = "Isolated Web Co"
def site_pids(processes, engine_dir):
"""The pids of the processes of the engine, among `processes` (psutil-like), that host a site."""
import psutil
pids = set()
for child in psutil.Process(os.getpid()).children(recursive=True):
for proc in processes:
try:
if not os.path.normcase(child.exe()).startswith(os.path.normcase(engine_dir)):
if not os.path.normcase(proc.exe()).startswith(os.path.normcase(engine_dir)):
continue
cmd = child.cmdline()
name, cmd = proc.name(), proc.cmdline()
except psutil.Error:
continue
if "-contentproc" in cmd and cmd[-1] == "tab":
pids.add(child.pid)
if "-contentproc" in cmd and cmd[-1] == "tab" and name == SITE_PROCESS_NAME:
pids.add(proc.pid)
return pids
def site_processes(engine_dir):
"""The pids of the engine's processes below this test that host a site (see the module's docstring)."""
import psutil
if not sys.platform.startswith("linux"):
pytest.skip("only Linux names a content process by the site it hosts; %s names none" % sys.platform)
return site_pids(psutil.Process(os.getpid()).children(recursive=True), engine_dir)
def quiet(engine_dir, seconds=3.0, limit=30.0):
"""The set of content processes once it has not changed for `seconds`."""
"""The set of the processes that host a site, once it has not changed for `seconds`."""
end = time.time() + limit
last, since = content_processes(engine_dir), time.time()
last, since = site_processes(engine_dir), time.time()
while time.time() < end:
time.sleep(0.25)
now = content_processes(engine_dir)
now = site_processes(engine_dir)
if now != last:
last, since = now, time.time()
elif time.time() - since >= seconds:
@@ -218,18 +238,19 @@ def test_cross_site_iframe_gets_its_own_process(page, cross_site_loop, engine_di
assert wait_for(page, lambda: any(r["path"] == "/report/loaded" and r["host"] == "a.test" and
r["query"]["path"] == ["/leaf"] for r in cross_site_loop["reports"]))
after = quiet(engine_dir)
assert len(after - before) >= 1, "no new content process: before %s, after %s" % (sorted(before), sorted(after))
assert len(after - before) >= 1, "no new process for a site: before %s, after %s" % (sorted(before), sorted(after))
@pytest.mark.e2e
def test_same_site_other_port_stays_in_process(page, cross_site_loop, engine_dir):
"""Green today, the control: a frame of the page's own site adds no content process."""
"""Green today, the control: a frame of the page's own site adds no process for a site, and the page stays
in the process it was in."""
page.goto(cross_site_loop["plain"])
before = quiet(engine_dir)
page.goto(cross_site_loop["same_site"], wait_until="load")
assert wait_for(page, lambda: any(r["path"] == "/report/loaded" for r in cross_site_loop["reports"]))
after = quiet(engine_dir)
assert not (after - before), "a same-site frame started a process: %s" % sorted(after - before)
assert after == before, "a same-site frame changed the processes of the sites: %s -> %s" % (sorted(before), sorted(after))
# ── 3 .. 10: what the product does not do yet ──────────────────────────────────
@@ -0,0 +1,57 @@
"""The Fission bench counts the processes that host a site, not every content process that is new. No browser.
The engine keeps preallocated content processes and starts one to refill the pool after it hands one to a site,
whenever it gets to it. The bench counted every `-contentproc ... tab` pid, so a refill that landed between its
two reads was "a process the same-site frame started" (test_same_site_other_port_stays_in_process, red on the
e2e of the commit of 0.50.0: `[13443]`). The processes below are the ones measured on firefox-62 (Linux):
names and command lines as /proc gives them.
"""
import pytest
import test_fission_strategy1_bench as bench
pytestmark = pytest.mark.unit
ENGINE = "/cache/firefox-62/firefox"
DIR = "/cache/firefox-62"
class _Proc:
def __init__(self, pid, name, kind, exe=ENGINE):
self.pid, self._name, self._exe = pid, name, exe
self._cmd = [exe, "-contentproc", "-isForBrowser", "-prefsLen", "1", "-parentBuildID", "20261111073531",
"-appDir", DIR + "/browser", str(pid), kind]
def exe(self):
return self._exe
def name(self):
return self._name
def cmdline(self):
return self._cmd
def _engine_at_plain():
"""a.test/plain shown: one process for the site, three preallocated, and the engine's other children."""
return [_Proc(184, "Socket Process", "socket"), _Proc(200, "WebExtensions", "tab"),
_Proc(334, "Isolated Web Co", "tab"), _Proc(377, "Privileged Cont", "tab"),
_Proc(433, "Web Content", "tab"), _Proc(438, "Web Content", "tab"), _Proc(460, "Web Content", "tab")]
def test_a_preallocated_process_that_arrives_is_not_a_site():
before = bench.site_pids(_engine_at_plain(), DIR)
after = bench.site_pids(_engine_at_plain() + [_Proc(549, "Web Content", "tab")], DIR)
assert before == after == {334}
def test_a_preallocated_process_given_to_a_site_is_a_new_site_process():
"""A cross-site frame: 433 leaves the pool for b.test (and is renamed), 549 refills the pool."""
procs = [p for p in _engine_at_plain() if p.pid != 433]
procs += [_Proc(433, "Isolated Web Co", "tab"), _Proc(549, "Web Content", "tab")]
assert bench.site_pids(procs, DIR) - bench.site_pids(_engine_at_plain(), DIR) == {433}
def test_a_process_of_another_firefox_is_not_counted():
other = _Proc(900, "Isolated Web Co", "tab", exe="/usr/lib/firefox/firefox")
assert bench.site_pids(_engine_at_plain() + [other], DIR) == {334}