"""Releasing many kernels at once on a saturated machine confirms every stop. python3 e2e/run.py ../test/manual/kernel_stop_load.py STOP_LOAD_SESSIONS and STOP_LOAD_BURNERS set the kernels and the CPU burners. It takes about 16 s and saturates every core, so it is not in the gate; the helper's concurrent stops are checked there by signal_helper_test. A stop ends the kernel's process groups through a helper. When the helper was a fresh Python interpreter per stop, a burst of stops competed with the kernel boots for the CPU, missed its deadline, and left the session refusing to open ("previous kernel stop is unconfirmed"). Only a real daemon with real kernels under CPU load shows that, so this runs through an inspected daemon. """ import json import os from pathlib import Path import subprocess import sys import unittest sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "e2e")) from harness import ROOT, Albedo, Provider, exclusive, python, text # noqa: E402 from inspect_support import Inspection # noqa: E402 SESSIONS = int(os.environ.get("STOP_LOAD_SESSIONS", "24")) BURNERS = int(os.environ.get("STOP_LOAD_BURNERS", str(os.cpu_count() or 4))) @exclusive class StopUnderLoadTests(unittest.TestCase): def test_a_burst_of_stops_on_a_busy_machine_confirms_every_kernel(self): def script(request): if request["messages"][-1].get("role") == "tool": return text("ready") return python("sentinel = 1") provider = Provider(script) self.addCleanup(provider.close) def prepare(app): app.daemon.env["ALBEDO_INSPECT"] = "1" with Albedo(provider, prepare=prepare) as app: sessions = [app.session() for _ in range(SESSIONS)] for session in sessions: app.prompt(session, "boot").close() for session in sessions: app.idle(session) burners = [ subprocess.Popen([sys.executable, "-c", "while True: pass"]) for _ in range(BURNERS) ] try: probe = Inspection(app, ROOT / "test/manual/albedo_stop_load_probe.erl") ids = ",".join(f'<<"{session}">>' for session in sessions) report = json.loads( probe.evaluate( "io:put_chars(Call(albedo_stop_load_probe, mass_json, " f'[[{ids}], <<"{app.workspace}">>]))', timeout=180, ) ) finally: for burner in burners: burner.kill() self.assertEqual(report["failed"], 0, report) log = (app.home / "daemon.log").read_text(errors="replace") self.assertNotIn("termination helper", log)