Kill the mutants of the stuck check, its rung and the /proc readings it hands the investigation

This commit is contained in:
2026-11-19 09:06:26 +01:00
parent 6b8fbc6ff5
commit a12710ebc4
3 changed files with 69 additions and 29 deletions
+22 -12
View File
@@ -190,20 +190,30 @@ class ChildShells(unittest.TestCase):
self.assertEqual(self.shell_of(to_pipe).written, self.shell_of(to_pipe).started)
def test_reads_the_end_of_a_shells_output_file_and_nothing_from_a_pipe(self):
with tempfile.NamedTemporaryFile() as output:
output.write(b"x" * child_shells.OUTPUT_BYTES + b"last line\n")
output.flush()
to_file = self.started("sleep 60; true", stdout=output)
to_pipe = self.started("sleep 60; true", stdout=subprocess.PIPE)
self.assertEqual(self.shell_of(to_file).output, "x" * (child_shells.OUTPUT_BYTES - 10) + "last line\n")
self.assertEqual(self.shell_of(to_pipe).output, "")
for written, want in ((b"x" * child_shells.OUTPUT_BYTES + b"last line\n", "x" * (child_shells.OUTPUT_BYTES - 10) + "last line\n"), (b"short \xff\n", "short \ufffd\n")):
with self.subTest(want=want[-12:]), tempfile.NamedTemporaryFile() as output:
output.write(written)
output.flush()
self.assertEqual(self.shell_of(self.started("sleep 60; true", stdout=output)).output, want)
self.assertEqual(self.shell_of(self.started("sleep 60; true", stdout=subprocess.PIPE)).output, "")
def test_reads_each_process_below_a_shell_and_the_cpu_the_whole_tree_used(self):
busy = self.started("timeout 5 sh -c 'while :; do :; done'; true")
wait_until(lambda: self.shell_of(busy).cpu > 0.1)
def test_reads_nothing_of_a_process_that_is_gone(self):
gone = subprocess.Popen(["true"])
gone.wait()
self.assertEqual((child_shells.cpu_and_state(gone.pid), child_shells.output_tail(gone.pid)), ((0.0, "gone"), ""))
def test_reads_each_process_below_a_shell_and_the_user_and_kernel_cpu_the_whole_tree_used(self):
# dd from /dev/zero spends its time in the kernel, and the sleep after it uses none, so the total must add both modes of every process.
busy = self.started("dd if=/dev/zero of=/dev/null bs=1M & sleep 60; true")
wait_until(lambda: len(child_shells.descendants(busy.pid)) == 2)
before, started = self.shell_of(busy).cpu, time.monotonic()
time.sleep(1)
used = self.shell_of(busy).cpu - before
self.assertGreater(used, 0.2 * (time.monotonic() - started))
self.assertLess(used, 1.5 * (time.monotonic() - started))
processes = self.shell_of(busy).processes
self.assertEqual([line.split(" ", 4)[4] for line in processes], ["timeout 5 sh -c while :; do :; done", "sh -c while :; do :; done"])
self.assertEqual(processes[1].split(" ")[1], "R")
self.assertEqual([line.split(" ", 4)[4] for line in processes], ["dd if=/dev/zero of=/dev/null bs=1M", "sleep 60"])
self.assertEqual([line.split(" ")[1] for line in processes], ["R", "S"])
def test_stops_a_shell_and_the_process_it_started_and_no_other(self):
shell = self.started("sleep 60; true")