"""Creating a session walks its source files at most three times, cheaply. A session's first observation has no retained discovery: it reads every skill and instruction file for the key and once more to check that nothing changed while it discovered (two walks); a later observation of the same session re-checks the retained discovery with one. Discovery also used to walk once more inside, a fourth. A walk resolves every skill's directory and file one path component at a time, which cost over a thousand link lookups for one new session (walk and discovery) before each looked a shared component up once. On a loaded machine each lookup waits for the CPU, so the extra walk and the repeated lookups pushed session writes past the observation's deadline (503). Only the daemon's real runtime shows how many times it walked, so this runs through an inspected daemon. """ import unittest from harness import ROOT, Albedo, Provider, exclusive, text from inspect_support import Inspection @exclusive class ObservationWalkTests(unittest.TestCase): def test_a_new_session_walks_its_sources_no_more_than_three_times(self): provider = Provider(lambda request: text("ok")) self.addCleanup(provider.close) def prepare(app): app.daemon.env["ALBEDO_INSPECT"] = "1" with Albedo(provider, prepare=prepare) as app: probe = Inspection(app, ROOT / "test/e2e/albedo_observe_probe.erl") probe.call_json("trace_start") app.session() report = probe.call_json("trace_stop") self.assertGreaterEqual(report["walks"], 1, report) self.assertLessEqual(report["walks"], 3, report) self.assertLessEqual(report["link_lookups"], 300, report) if __name__ == "__main__": unittest.main()