Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263"""Catch an interrupt record outliving the cell it was for.
An interrupt that reaches a cell still queued is remembered until the cellstarts. A cell refused at the cell limit never starts, so only a check insidea real kernel, with the queue held behind a running cell, sees whether therecord was dropped with it."""
import unittest
from remote_kernel_test import OwnerChannel
LIMIT_ONE = """import albedo_cells as kernelkernel.BACKGROUND_SECONDS = 0.2kernel.LIMITS["cell"] = 1"""HOLD = "import asyncio\nawait asyncio.sleep(1.5)\n"INSPECT = "print('pending', sorted(kernel.INTERRUPTS))\n"
class CellInterruptsTest(unittest.TestCase): def setUp(self): self.channel = OwnerChannel([]) self.addCleanup(self.channel.close) self.assertEqual(self.channel.recv()["type"], "ready")
def done(self, id, code): self.channel.send({"type": "execute", "id": id, "code": code}) return self.channel.wait_for( lambda frame: ( frame["type"] == "done" and frame["id"] == id and frame["status"] != "backgrounded" ) )
def test_an_interrupted_cell_refused_at_the_cell_limit_leaves_no_record(self): self.assertEqual(self.done("limit", LIMIT_ONE)["status"], "ok") self.channel.send({"type": "execute", "id": "hold", "code": HOLD}) # The serving loop waits on "hold" until it is backgrounded, so the # next cell is queued, and the interrupt finds it there. self.channel.send({"type": "execute", "id": "refused", "code": "pass"}) self.channel.send({"type": "interrupt", "id": "refused", "reason": "cancelled"}) refused = self.channel.wait_for( lambda frame: frame["type"] == "done" and frame["id"] == "refused" ) self.assertIn("16 cells are still running", refused["output"]) wake = self.channel.wait_for( lambda frame: ( frame["type"] == "call" and frame.get("method") == "cells.completed" ) ) self.channel.send( {"type": "reply", "id": wake["id"], "value": {"ok": True, "value": None}} ) inspected = self.done("inspect", INSPECT) self.assertIn("pending []", inspected["output"], inspected)
if __name__ == "__main__": unittest.main()