Skip to content

Commit

Permalink
Fix race condition in test.
Browse files Browse the repository at this point in the history
test_sub_sock_options was relying on a race condition, where the
background thread would receive the first message before the second was
actually sent.  This happened because I incorrectly believed the message
buffer depth was greater than 1 by default, so I did not realize it was
a race condition.
  • Loading branch information
codypiersall committed Apr 6, 2019
1 parent c1d068d commit f1c5013
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ def test_pair1_polyamorousness():
def test_sub_sock_options():
with pynng.Pub0(listen=addr) as pub:
# test single option topic
with pynng.Sub0(dial=addr, topics='beep') as sub:
with pynng.Sub0(dial=addr, topics='beep', recv_timeout=500) as sub:
wait_pipe_len(sub, 1)
pub.send(b'beep hi')
assert sub.recv() == b'beep hi'
with pynng.Sub0(dial=addr, topics=['beep', 'hello']) as sub:
with pynng.Sub0(dial=addr, topics=['beep', 'hello'],
recv_timeout=500) as sub:
wait_pipe_len(sub, 1)
pub.send(b'beep hi')
pub.send(b'hello there')
assert sub.recv() == b'beep hi'
pub.send(b'hello there')
assert sub.recv() == b'hello there'

0 comments on commit f1c5013

Please # to comment.