Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
 async def create(conf, engine):
     module = Module()
     module._async_group = aio.Group()
     module._subscription = common.Subscription([['*']])
     return module
Ejemplo n.º 3
0
 async def _process_msg_subscribe(self, msg):
     self._subscription = common.Subscription(
         [tuple(i) for i in msg.data.data])
Ejemplo n.º 4
0
def test_subscription_isdisjoint(first, second, isdisjoint):
    first = common.Subscription(first)
    second = common.Subscription(second)
    result = first.isdisjoint(second)
    assert result is isdisjoint
Ejemplo n.º 5
0
def test_subscription_union(query_types, union):
    subscription = common.Subscription([]).union(*(common.Subscription(i)
                                                   for i in query_types))
    result = subscription.get_query_types()
    assert set(result) == set(union)
Ejemplo n.º 6
0
def test_subscription_matches(query_types, matching, not_matching):
    subscription = common.Subscription(query_types)
    for i in matching:
        assert subscription.matches(i) is True
    for i in not_matching:
        assert subscription.matches(i) is False
Ejemplo n.º 7
0
def test_subscription_get_query_types(query_types, sanitized):
    subscription = common.Subscription(query_types)
    result = list(subscription.get_query_types())
    assert len(result) == len(sanitized)
    assert {tuple(i) for i in result} == {tuple(i) for i in sanitized}
Ejemplo n.º 8
0
def _filter_event_types(events, event_types):
    subscription = common.Subscription(event_types)
    for event in events:
        if subscription.matches(event.event_type):
            yield event