Keep a worker's shells that run a busy tool, name the shell's real command and fix the review's prose findings

This commit is contained in:
2026-11-18 17:20:13 +01:00
parent 72ffb9f748
commit abae3a0559
8 changed files with 96 additions and 50 deletions
+36 -12
View File
@@ -139,21 +139,45 @@ class PythonEffect(unittest.TestCase):
class ChildShells(unittest.TestCase):
def test_reads_a_child_shell_with_its_command_and_a_heavy_slot_and_stops_it_with_what_it_started(self):
quiet = subprocess.Popen(["bash", "-c", "sleep 60; true"])
heavy = subprocess.Popen(["bash", "-c", "sleep 60; true # run-heavy"])
def test_reads_a_child_shells_command_and_whether_a_busy_tool_runs_below_it(self):
with tempfile.TemporaryDirectory() as folder:
tool = pathlib.Path(folder, "chunk-pr")
tool.write_text("#!/bin/sh\nsleep 60\n")
tool.chmod(0o755)
# Like the shell of a loop that only names the tool, as the one that held a worker on 2026-11-18 did.
naming = subprocess.Popen(["bash", "-c", "source /dev/null && eval 'until false; do sleep 60; done # chunk-pr merge'"])
busy = subprocess.Popen(["bash", "-c", f"{tool} merge; true"])
other = subprocess.Popen(["sleep", "60"])
try:
time.sleep(0.5)
shells = {shell.pid: shell for shell in child_shells.shells_of(os.getpid())}
self.assertEqual(sorted(shells), sorted([naming.pid, busy.pid]))
self.assertEqual(shells[naming.pid].command, "until false; do sleep 60; done # chunk-pr merge")
self.assertEqual((shells[naming.pid].runs_busy_tool, shells[busy.pid].runs_busy_tool), (False, True))
self.assertLess(abs(shells[naming.pid].started - time.time()), 5)
finally:
for proc in (naming, busy, other):
proc.kill()
proc.wait()
def test_stops_a_shell_and_the_process_it_started_and_no_other(self):
shell = subprocess.Popen(["bash", "-c", "sleep 60; true"])
other = subprocess.Popen(["sleep", "60"])
try:
time.sleep(0.3)
shells = {shell.pid: shell for shell in child_shells.shells_of(os.getpid())}
self.assertEqual(sorted(shells), sorted([quiet.pid, heavy.pid]))
self.assertEqual(shells[quiet.pid].command, "bash -c sleep 60; true")
self.assertEqual((shells[quiet.pid].holds_slot, shells[heavy.pid].holds_slot), (False, True))
self.assertLess(abs(shells[quiet.pid].started - time.time()), 5)
child_shells.stop(shells[quiet.pid])
self.assertEqual(quiet.wait(timeout=5), -signal.SIGTERM)
time.sleep(0.5)
found = child_shells.shells_of(os.getpid())
[stopping] = [each for each in found if each.pid == shell.pid]
below = child_shells.descendants(shell.pid)
self.assertEqual(len(below), 1)
child_shells.stop(stopping)
self.assertEqual(shell.wait(timeout=5), -signal.SIGTERM)
for _ in range(50):
if not os.path.exists(f"/proc/{below[0]}"):
break
time.sleep(0.1)
self.assertFalse(os.path.exists(f"/proc/{below[0]}"))
self.assertIsNone(other.poll())
finally:
for proc in (quiet, heavy, other):
for proc in (shell, other):
proc.kill()
proc.wait()