async def test_without_subscribe(comm_address, comm_conf): event_types = [(), ('a', ), ('b', ), ('a', 'a'), ('a', 'b'), ('a', 'b', 'c'), ('', '', '')] events = [ hat.event.common.Event(event_id=hat.event.common.EventId(server=0, instance=i), event_type=event_type, timestamp=common.now(), source_timestamp=None, payload=None) for i, event_type in enumerate(event_types) ] engine = ModuleEngine() comm = await hat.event.server.communication.create(comm_conf, engine) client = await hat.event.client.connect(comm_address) await client.query(common.QueryData()) engine.notify(events) with pytest.raises(asyncio.TimeoutError): await asyncio.wait_for(client.receive(), 0.01) await client.async_close() await comm.async_close() await engine.async_close()
async def test_query(comm_address, comm_conf): event_types = [(), ('a', ), ('b', ), ('a', 'a'), ('a', 'b'), ('a', 'b', 'c'), ('', '', '')] events = [ hat.event.common.Event(event_id=hat.event.common.EventId(server=0, instance=i), event_type=event_type, timestamp=common.now(), source_timestamp=None, payload=None) for i, event_type in enumerate(event_types) ] query_data = common.QueryData() query_queue = aio.Queue() def query_cb(data): query_queue.put_nowait(data) return events engine = ModuleEngine(query_cb=query_cb) comm = await hat.event.server.communication.create(comm_conf, engine) client = await hat.event.client.connect(comm_address) result = await client.query(query_data) assert result == events temp_query_data = await query_queue.get() assert temp_query_data == query_data await client.async_close() await comm.async_close() await engine.async_close()
async def test_subscribe(comm_address, comm_conf, subscriptions): subscription = common.Subscription(subscriptions) event_types = [[], ['a'], ['b'], ['a', 'a'], ['a', 'b'], ['a', 'b', 'c'], ['', '', '']] filtered_event_types = [ event_type for event_type in event_types if subscription.matches(event_type) ] events = [ hat.event.common.Event(event_id=hat.event.common.EventId(server=0, instance=i), event_type=event_type, timestamp=common.now(), source_timestamp=None, payload=None) for i, event_type in enumerate(event_types) ] engine = ModuleEngine() comm = await hat.event.server.communication.create(comm_conf, engine) client = await hat.event.client.connect(comm_address, subscriptions) await client.query(common.QueryData()) # process `Subscribe` message engine.notify(events) if filtered_event_types: events = await client.receive() assert ({tuple(i.event_type) for i in events} == {tuple(i) for i in filtered_event_types}) await client.async_close() await comm.async_close() await engine.async_close()
async def test_query(backend_module_name, create_backend_module): conf = {'server_id': 123, 'backend': {'module': backend_module_name}} event_ids = [common.EventId(conf['server_id'], i) for i in range(10)] events = [ common.Event(event_id=event_id, event_type=[], timestamp=common.now(), source_timestamp=None, payload=None) for event_id in event_ids ] query_data = common.QueryData() def query(data): assert query_data == data return events with create_backend_module(query_cb=query): engine = await hat.event.server.backend_engine.create(conf) result = await engine.query(query_data) assert result == events await engine.async_close()
async def test_query(): query_data = common.QueryData() events = [ common.Event(event_id=common.EventId(1, i), event_type=(), timestamp=common.now(), source_timestamp=None, payload=None) for i in range(10) ] def on_query(data): assert data == query_data return events conf = {'modules': []} backend = BackendEngine(query_cb=on_query) engine = await hat.event.server.module_engine.create(conf, backend) result = await engine.query(query_data) assert result == events await engine.async_close() await backend.async_close()
@pytest.mark.parametrize("event_count", [0, 1, 5, 10]) async def test_register(event_count): events = [ hat.event.common.Event(event_id=hat.event.common.EventId(server=0, instance=i), event_type=(), timestamp=common.now(), source_timestamp=None, payload=None) for i in range(event_count) ] conf = {'module': 'hat.event.server.backends.dummy'} backend = await hat.event.server.backends.dummy.create(conf) result = await backend.register(events) assert result == events await backend.async_close() @pytest.mark.parametrize("query_data", [common.QueryData()]) async def test_query(query_data): conf = {'module': 'hat.event.server.backends.dummy'} backend = await hat.event.server.backends.dummy.create(conf) result = await backend.query(query_data) assert result == [] await backend.async_close()
type=common.EventPayloadType.BINARY, data=b'123')), common.RegisterEvent( event_type=('a', 'b', 'c'), source_timestamp=common.now(), payload=common.EventPayload( type=common.EventPayloadType.JSON, data=None)), common.RegisterEvent( event_type=('a', 'b', 'c'), source_timestamp=common.now(), payload=common.EventPayload( type=common.EventPayloadType.JSON, data=[{}, None, [], True, False, 1, 2.5, "123"])) ]) def test_register_event_sbs(register_event): encoded = common.register_event_to_sbs(register_event) decoded = common.register_event_from_sbs(encoded) assert decoded == register_event @pytest.mark.parametrize("query", [ common.QueryData() ]) def test_query_sbs(query): encoded = common.query_to_sbs(query) decoded = common.query_from_sbs(encoded) assert decoded == query