Skip to content

Commit

Permalink
Add test for SYNC_PUB topic handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Alonso committed Jun 29, 2017
1 parent 056b806 commit c735550
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions osbrain/tests/test_agent_sync_publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,40 @@ def on_error(agent):
agent.error_log.append('error')


def test_change_subscription_topics_sync(nsproxy):
'''
Test for the different options of subscribing/unsubscribing to topics
in the SYNC_PUB/SYNC_SUB pattern.
'''
server = run_agent('server')
client = run_agent('client')

addr = server.bind('SYNC_PUB', alias='pub', handler=lambda: None)
client.set_attr(received=[])
client.connect(addr, alias='sub', handler=receive)

# Stablish a connection
server.each(0.1, 'send', 'pub', 'connecting...')
assert wait_agent_attr(client, name='received', data='connecting...')

# By default, client will be subscribed to all topics
server.send('pub', 'hello')
assert wait_agent_attr(client, name='received', data='hello')

# Only subscribe to 'TOP' topic
client.unsubscribe_socket_from_topic('sub', b'')
client.subscribe_socket_to_topic('sub', b'TOP')

# Message not received since 'TOP' topic not specified in the send call
server.send('pub', 'world')
assert not wait_agent_attr(client, name='received', data='world',
timeout=1)

# Receive message with the topic we are subscribed to
server.send('pub', 'ten', topic='TOP')
assert wait_agent_attr(client, name='received', data='ten')


@pytest.mark.parametrize('server', [Server, PubServer])
def test_simple_pub_single_handler(nsproxy, server):
"""
Expand Down

0 comments on commit c735550

Please sign in to comment.