Answer stability round 1: 1 🔴, 4 🟡 (1 misread); keep a shell whose command holds a heavy slot, and say a failed record write on stderr

This commit is contained in:
2026-11-18 20:12:40 +01:00
parent abae3a0559
commit a7439c2e00
6 changed files with 108 additions and 66 deletions
+16 -6
View File
@@ -814,12 +814,22 @@ class LingeringWorkers(unittest.TestCase):
streamed, _, _ = self.worker_with(self.RESULT, None, held=[self.shell(), busy])
self.assertEqual(streamed.stopped, [])
def test_a_worker_keeps_its_shells_until_its_result_has_stood_longer_than_the_settled_time(self):
fake = FakeEffects()
effects = dataclasses.replace(fake.effects(), now=lambda: NOW + lingering_workers.SETTLED)
proc = Streamed(0, held=[self.shell()])
lingering_workers.stopped_shells(proc, NOW, pathlib.Path("/unused"), effects)
self.assertEqual(proc.stopped, [])
def test_a_worker_keeps_a_shell_that_wrote_within_the_quiet_time_and_stops_one_that_wrote_before_it(self):
# The check comes 300 s after the result, so a shell written at NOW + 300 - QUIET is the latest that is still kept.
kept = self.shell(written=NOW + 300 - lingering_workers.QUIET)
stopped = self.shell(written=NOW + 300 - lingering_workers.QUIET - 1)
self.assertEqual(self.worker_with(self.RESULT, None, held=[kept])[0].stopped, [])
self.assertEqual(self.worker_with(self.RESULT, None, held=[stopped])[0].stopped, [stopped])
def test_a_stop_that_cannot_be_recorded_is_said_on_stderr_and_every_shell_is_still_stopped(self):
clock = [NOW]
held = [self.shell(), self.shell()]
streamed = Streamed(0, self.RESULT, None, clock=clock, held=held)
effects = dataclasses.replace(FakeEffects(streams=[streamed]).effects(), now=lambda: clock[0])
with tempfile.NamedTemporaryFile() as blocker, contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()) as failed:
worker.run_worker("/r", [], {}, pathlib.Path(blocker.name), effects)
self.assertEqual(streamed.stopped, held)
self.assertIn("could not record the stop", failed.getvalue())
class MemoryWait(unittest.TestCase):