"""A session an invalidation names is heard from the moment it is published. A collection stream learns which sessions it follows from a database listing it runs after each invalidation. A child's first activity or mail, published before that listing finished, matched no filter and was dropped, and nothing replayed it: under load a client following every session missed the new child's first events (a suite failed on one of roughly twenty runs). The bus admits the named sessions into every filter as it publishes the invalidation. Only the daemon's real bus shows what a subscriber is admitted, so this runs through an inspected daemon. """ import unittest from harness import ROOT, Albedo, Provider, exclusive, text from inspect_support import Inspection @exclusive class BusFilterTests(unittest.TestCase): def test_an_invalidated_session_is_admitted_before_the_filter_refreshes(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 / "e2e/albedo_bus_filter_probe.erl") report = probe.call_json("invalidated_session_events") self.assertEqual( report["events"], ["invalidate child", "child activity", "mail to child"], ) self.assertTrue(report["invalidated"]) def test_stale_refresh_preserves_new_members_until_a_fresh_refresh(self): self.check_probe( "stale_refresh", { "before": ["invalidate child", "child activity", "child mail"], "global": ["global invalidate", "after global invalidate"], "after_refresh": [], "closed": [], }, ) def test_membership_retains_sessions_that_move_above_a_page_cursor(self): self.check_probe( "moving_membership", { "tail_count": 4, "count": 205, "moved_present": True, "frequent_count": 205, }, ) def check_probe(self, function, expected): 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 / "e2e/albedo_bus_filter_probe.erl") self.assertEqual(probe.call_json(function), expected) if __name__ == "__main__": unittest.main()