Skip to content

Commit

Permalink
Rename receive to append_received
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Alonso committed Jun 29, 2017
1 parent 503c396 commit 9cd6f45
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion osbrain/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from osbrain.helper import sync_agent_logger


def receive(agent, message, topic=None):
def append_received(agent, message, topic=None):
agent.received.append(message)


Expand Down
8 changes: 4 additions & 4 deletions osbrain/tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from osbrain.helper import wait_agent_attr

from common import nsproxy # pragma: no flakes
from common import receive
from common import append_received
from common import set_received


Expand Down Expand Up @@ -196,7 +196,7 @@ def on_init(self):
puller = run_agent('puller', base=AgentTest)
pusher = run_agent('pusher', base=AgentTest)

address = puller.bind('PULL', alias='pull', handler=receive,
address = puller.bind('PULL', alias='pull', handler=append_received,
transport='tcp')

pusher.connect(address, alias='push')
Expand All @@ -210,8 +210,8 @@ def on_init(self):
time.sleep(sleep_time)

puller = run_agent('puller', base=AgentTest)
puller.bind('PULL', alias='pull', handler=receive, addr=address.address,
transport='tcp')
puller.bind('PULL', alias='pull', handler=append_received,
addr=address.address, transport='tcp')

assert should_receive == wait_agent_attr(puller, data='foo', timeout=.2)

Expand Down
8 changes: 4 additions & 4 deletions osbrain/tests/test_agent_async_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from osbrain.helper import logger_received

from common import nsproxy # pragma: no flakes
from common import receive
from common import append_received


def on_error(agent):
Expand Down Expand Up @@ -40,7 +40,7 @@ def late_reply(agent, request):
client = run_agent('client', base=Client)

addr = server.bind('ASYNC_REP', alias='replier', handler=late_reply)
client.connect(addr, alias='async', handler=receive)
client.connect(addr, alias='async', handler=append_received)

return (server, client)

Expand All @@ -56,7 +56,7 @@ def late_reply(agent, delay):
client = run_agent('client', base=Client)

addr = server.bind('ASYNC_REP', alias='replier', handler=late_reply)
client.connect(addr, alias='async', handler=receive)
client.connect(addr, alias='async', handler=append_received)

return (server, client)

Expand Down Expand Up @@ -102,7 +102,7 @@ def late_reply(agent, request):
client = run_agent('client', base=Client)

addr = server.bind('ASYNC_REP', alias='replier', handler=late_reply)
client.connect(addr, alias='async', handler=receive)
client.connect(addr, alias='async', handler=append_received)

# Client requests should be non-blocking
t0 = time.time()
Expand Down
12 changes: 6 additions & 6 deletions osbrain/tests/test_agent_async_requests_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from osbrain.helper import wait_agent_attr

from common import nsproxy # pragma: no flakes
from common import receive
from common import append_received


class Server_ASYNC_REP(Agent):
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_async_rep_handler_exists(nsproxy):

@pytest.mark.parametrize(
'handler',
['reply', receive, lambda a, x: a.received.append(x)]
['reply', append_received, lambda a, x: a.received.append(x)]
)
def test_async_rep_handler_types(nsproxy, handler):
'''
Expand All @@ -62,7 +62,7 @@ def test_async_rep_handler_types(nsproxy, handler):
@pytest.mark.parametrize(
'handler, check_function',
[('receive_method', False),
(receive, True),
(append_received, True),
(lambda a, x: a.received.append(x), False)])
def test_async_rep_connect_handler_types(nsproxy, handler, check_function):
'''
Expand All @@ -85,14 +85,14 @@ def test_async_rep_connect_handler_types(nsproxy, handler, check_function):
if check_function:
# Check that the function was not stored as a method for the object
with pytest.raises(AttributeError) as error:
assert client.get_attr('receive')
assert client.get_attr('append_received')
assert 'object has no attribute' in str(error.value)


@pytest.mark.parametrize(
'handler, check_function',
[('receive_method', False),
(receive, True),
(append_received, True),
(lambda a, x: a.received.append(x), False)])
def test_async_rep_send_handler_types(nsproxy, handler, check_function):
'''
Expand All @@ -113,5 +113,5 @@ def test_async_rep_send_handler_types(nsproxy, handler, check_function):
if check_function:
# Check that the function was not stored as a method for the object
with pytest.raises(AttributeError) as error:
assert client.get_attr('receive')
assert client.get_attr('append_received')
assert 'object has no attribute' in str(error.value)
26 changes: 13 additions & 13 deletions osbrain/tests/test_agent_pubsub_topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from osbrain.address import AgentAddressSerializer

from common import nsproxy # pragma: no flakes
from common import receive
from common import append_received


@pytest.mark.parametrize(
Expand All @@ -33,12 +33,12 @@ def test_pubsub_topics_separator(nsproxy, serializer):

addr = a0.bind('PUB', alias='pub', serializer=serializer)

a1.connect(addr, handler=receive)
a2.connect(addr, handler={'foo': receive})
a3.connect(addr, handler={'bar': receive,
'foo': receive})
a4.connect(addr, handler={'bar': receive})
a5.connect(addr, handler={'fo': receive})
a1.connect(addr, handler=append_received)
a2.connect(addr, handler={'foo': append_received})
a3.connect(addr, handler={'bar': append_received,
'foo': append_received})
a4.connect(addr, handler={'bar': append_received})
a5.connect(addr, handler={'fo': append_received})

# Give some time for all the agents to connect
time.sleep(0.1)
Expand Down Expand Up @@ -113,12 +113,12 @@ def test_pubsub_topics_raw(nsproxy, serializer):

addr = a0.bind('PUB', alias='pub', serializer=serializer)

a1.connect(addr, handler=receive)
a2.connect(addr, handler={'foo': receive})
a3.connect(addr, handler={'bar': receive,
'foo': receive})
a4.connect(addr, handler={'bar': receive})
a5.connect(addr, handler={'fo': receive})
a1.connect(addr, handler=append_received)
a2.connect(addr, handler={'foo': append_received})
a3.connect(addr, handler={'bar': append_received,
'foo': append_received})
a4.connect(addr, handler={'bar': append_received})
a5.connect(addr, handler={'fo': append_received})

# Give some time for all the agents to connect
time.sleep(0.1)
Expand Down
29 changes: 17 additions & 12 deletions osbrain/tests/test_agent_sync_publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from osbrain.helper import wait_agent_attr

from common import nsproxy # pragma: no flakes
from common import receive
from common import append_received


class BaseServer(Agent):
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_simple_pub_single_handler(nsproxy, server):

# Connect clients
addr = server.addr('publish')
addr_alltopics = alltopics.connect(addr, handler=receive)
addr_alltopics = alltopics.connect(addr, handler=append_received)
assert addr_alltopics == addr.twin()

# Publish from server
Expand Down Expand Up @@ -130,10 +130,12 @@ def test_simple_pub_dict_handler(nsproxy, server):

# Connect clients
addr = server.addr('publish')
addr_both = both.connect(addr, handler={'positive': receive,
'negative': receive})
addr_positive = positive.connect(addr, handler={'positive': receive})
addr_bytestopic = bytestopic.connect(addr, handler={b'\xeb': receive})
addr_both = both.connect(addr, handler={'positive': append_received,
'negative': append_received})
addr_positive = positive.connect(addr,
handler={'positive': append_received})
addr_bytestopic = bytestopic.connect(addr,
handler={b'\xeb': append_received})
assert addr_both == addr.twin()
assert addr_positive == addr.twin()
assert addr_bytestopic == addr.twin()
Expand Down Expand Up @@ -186,8 +188,10 @@ def test_request(nsproxy, server):

# Connect clients
server_addr = server.addr('publish')
active_addr = active.connect(server_addr, alias='sub', handler=receive)
passive_addr = passive.connect(server_addr, alias='sub', handler=receive)
active_addr = active.connect(server_addr, alias='sub',
handler=append_received)
passive_addr = passive.connect(server_addr, alias='sub',
handler=append_received)
assert active_addr == server_addr.twin()
assert passive_addr == server_addr.twin()

Expand Down Expand Up @@ -246,7 +250,7 @@ def test_wait(nsproxy):

# Connect clients
server_addr = server.addr('publish')
client.connect(server_addr, alias='sub', handler=receive)
client.connect(server_addr, alias='sub', handler=append_received)

# Publish from server
server.each(0, 'publish')
Expand All @@ -257,14 +261,14 @@ def test_wait(nsproxy):

# Response received in time
fast = 0
client.send('sub', fast, handler=receive, wait=0.5)
client.send('sub', fast, handler=append_received, wait=0.5)
time.sleep(0.2)
assert server.get_attr('received') == [fast]
assert 'x' + str(fast) in client.get_attr('received')

# Response not received in time
slow = 1
client.send('sub', slow, handler=receive, wait=0.1)
client.send('sub', slow, handler=append_received, wait=0.1)
assert logger_received(logger,
log_name='log_history_warning',
message='not receive req',
Expand All @@ -274,7 +278,8 @@ def test_wait(nsproxy):

# Response not received in time with error handler
slow = 1
client.send('sub', slow, handler=receive, wait=0.1, on_error=on_error)
client.send('sub', slow, handler=append_received, wait=0.1,
on_error=on_error)
assert wait_agent_attr(client, name='error_log', length=1, timeout=0.5)
assert server.get_attr('received') == [fast, slow]
assert 'x' + str(slow) not in client.get_attr('received')
12 changes: 6 additions & 6 deletions osbrain/tests/test_agent_sync_publications_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from osbrain.helper import wait_agent_attr

from common import nsproxy # pragma: no flakes
from common import receive
from common import append_received


class Server_SYNC_PUB(Agent):
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_sync_pub_handler_exists(nsproxy):

@pytest.mark.parametrize(
'handler',
['reply', receive, lambda a, x: a.received.append(x)]
['reply', append_received, lambda a, x: a.received.append(x)]
)
def test_sync_pub_handler_types(nsproxy, handler):
'''
Expand All @@ -66,7 +66,7 @@ def test_sync_pub_handler_types(nsproxy, handler):
@pytest.mark.parametrize(
'handler, check_function',
[('receive_method', False),
(receive, True),
(append_received, True),
(lambda a, x: a.received.append(x), False)])
def test_sync_pub_connect_handler_types(nsproxy, handler, check_function):
'''
Expand All @@ -88,14 +88,14 @@ def test_sync_pub_connect_handler_types(nsproxy, handler, check_function):
if check_function:
# Check that the function was not stored as a method for the object
with pytest.raises(AttributeError) as error:
assert client.get_attr('receive')
assert client.get_attr('append_received')
assert 'object has no attribute' in str(error.value)


@pytest.mark.parametrize(
'handler, check_function, should_crash',
[('receive_method', False, False),
(receive, True, False),
(append_received, True, False),
(lambda a, x: a.received.append(x), False, False),
(None, False, True)])
def test_sync_pub_send_handlers(nsproxy, handler, check_function,
Expand Down Expand Up @@ -125,5 +125,5 @@ def test_sync_pub_send_handlers(nsproxy, handler, check_function,
if check_function:
# Check that the function was not stored as a method for the object
with pytest.raises(AttributeError) as error:
assert client.get_attr('receive')
assert client.get_attr('append_received')
assert 'object has no attribute' in str(error.value)
7 changes: 4 additions & 3 deletions osbrain/tests/test_agent_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from osbrain.helper import wait_agent_attr

from common import nsproxy # pragma: no flakes
from common import receive
from common import append_received


def test_agent_bind_transport_global(nsproxy):
Expand Down Expand Up @@ -105,8 +105,9 @@ def on_init(self):
# First agent run for directory `a`
os.chdir(dira)
a = run_agent('a', base=Wdagent)
random_addr = a.bind('PULL', transport='ipc', handler=receive)
set_addr = a.bind('PULL', addr='qwer', transport='ipc', handler=receive)
random_addr = a.bind('PULL', transport='ipc', handler=append_received)
set_addr = a.bind('PULL', addr='qwer', transport='ipc',
handler=append_received)

# Second agent run for directory `b`
os.chdir(dirb)
Expand Down
4 changes: 2 additions & 2 deletions osbrain/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from osbrain.helper import wait_agent_attr

from common import nsproxy # pragma: no flakes
from common import receive
from common import append_received


def since(t0, passed, tolerance):
Expand Down Expand Up @@ -301,7 +301,7 @@ def test_agent_proxy_oneway(nsproxy):
"""
class OneWayne(Agent):
def on_init(self):
target = self.bind('PULL', alias='target', handler=receive,
target = self.bind('PULL', alias='target', handler=append_received,
transport='inproc')
self.target = target
self.received = []
Expand Down

0 comments on commit 9cd6f45

Please sign in to comment.