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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106"""SIGTERM requests one drain and still exits when process slots run out.
A disposable VM exposes callback counts hidden by the daemon registry's ownshutdown guard. Exhausting that VM also tests both watchdog allocations withoutexhausting the test runner or relying on daemon timing."""
from pathlib import Pathimport subprocessimport tempfileimport unittest
ROOT = Path(__file__).resolve().parents[2]
EXHAUST = """Fill = fun F() -> try spawn(fun() -> receive stop -> ok end end) of _ -> F() catch error:system_limit -> ok endend,Fill()"""
class SigtermTests(unittest.TestCase): @classmethod def setUpClass(cls): cls.directory = tempfile.TemporaryDirectory(prefix="albedo-sigterm-test-") cls.addClassCleanup(cls.directory.cleanup) root = Path(cls.directory.name) # A failed watchdog allocation must not enter potentially blocking cleanup. cleanup = root / "albedo_code.erl" cleanup.write_text( "-module(albedo_code).\n-export([cleanup/0]).\n" "cleanup() -> receive stop -> ok end.\n" ) subprocess.run( [ "erlc", "-Wall", "-o", str(root), str(ROOT / "src/albedo/daemon/albedo_sigterm.erl"), str(cleanup), ], check=True, capture_output=True, text=True, )
def run_vm(self, expression): result = subprocess.run( [ "erl", "+S", "2:2", "+P", "1024", "-noshell", "-pa", self.directory.name, "-eval", expression, ], capture_output=True, text=True, timeout=20, ) self.assertEqual(result.returncode, 0, result.stdout + result.stderr) return result
def test_acknowledged_signals_request_the_drain_only_once(self): result = self.run_vm( """Owner = self(),{ok, nil} = albedo_sigterm:install(fun() -> Owner ! requested end, 1),ok = gen_event:sync_notify(erl_signal_server, sigterm),ok = gen_event:sync_notify(erl_signal_server, sigterm),receive requested -> ok after 1000 -> error(no_request) end,receive requested -> error(duplicate_request) after 0 -> ok end,io:format("one request~n"),erlang:halt(0).""" ) self.assertIn("one request", result.stdout)
def test_exhaustion_before_the_signal_does_not_block_in_cleanup(self): self.run_vm( "{ok, nil} = albedo_sigterm:install(fun() -> ok end, 1)," + EXHAUST + ", ok = gen_event:sync_notify(erl_signal_server, sigterm)," "error(signal_did_not_stop_vm)." )
def test_exhaustion_after_the_signal_does_not_disable_the_final_halt(self): self.run_vm( "{ok, nil} = albedo_sigterm:install(fun() -> ok end, 1)," "ok = gen_event:sync_notify(erl_signal_server, sigterm)," + EXHAUST + ", receive after infinity -> ok end." )
if __name__ == "__main__": unittest.main()