"""Spare kernels end with their owner, and a spare that cannot be stopped leaks no kernel.""" from pathlib import Path import unittest from harness import Albedo, exclusive_class from inspect_support import Inspection @exclusive_class class KernelSpareTests(unittest.TestCase): def test_unused_spares_end_on_stop_and_owner_death(self): with Albedo(prepare=lambda app: app.env.update(ALBEDO_INSPECT="1")) as app: probe = Inspection( app, Path(__file__).with_name("albedo_kernel_spare_probe.erl") ) self.assertTrue(probe.call_json("stop_json")["stopped"]) def test_a_spare_that_cannot_be_stopped_fails_the_open_without_leaking_its_kernel( self, ): with Albedo(prepare=lambda app: app.env.update(ALBEDO_INSPECT="1")) as app: session = app.session() probe = Inspection( app, Path(__file__).with_name("albedo_kernel_spare_probe.erl") ) result = probe.call_json( "stop_failure_json", f'[<<"{session}">>, <<"{app.workspace}">>]' ) self.assertTrue(result["failed"], result) self.assertEqual(result["booted"], 1, result) self.assertEqual(result["outlived"], 0, result)