From f1c50139a2dca3f545ee13135a1d67d4b072953f Mon Sep 17 00:00:00 2001 From: Cody Piersall Date: Sat, 6 Apr 2019 11:48:56 -0500 Subject: [PATCH] Fix race condition in test. 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. --- test/test_api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_api.py b/test/test_api.py index 50a0ded..e4cec89 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -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'