def test__handles_missing_notify_system_listener_on_notification(self): listener = PostgresListenerService() # Change notifications to a frozenset. This makes sure that # the system message does not go into the queue. Instead if should # call the handler directly in `doRead`. listener.notifications = frozenset() yield listener.startService() yield deferToDatabase(listener.registerChannel, "sys_test") try: yield deferToDatabase(self.send_notification, "sys_test", 1) self.assertFalse("sys_test" in listener.listeners) finally: yield listener.stopService()
def test__calls_system_handler_on_notification(self): listener = PostgresListenerService() # Change notifications to a frozenset. This makes sure that # the system message does not go into the queue. Instead if should # call the handler directly in `doRead`. listener.notifications = frozenset() dv = DeferredValue() listener.register("sys_test", lambda *args: dv.set(args)) yield listener.startService() try: yield deferToDatabase(self.send_notification, "sys_test", 1) yield dv.get(timeout=2) self.assertEqual(("sys_test", "1"), dv.value) finally: yield listener.stopService()