Skip to content

Commit 20f2493

Browse files
pytest speedups (#671)
this doesn't even add coverage
1 parent 4b3393a commit 20f2493

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

msgq/tests/test_messaging.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,33 @@ def test_conflate(self):
3838
sock = random_sock()
3939
pub_sock = msgq.pub_sock(sock)
4040
for conflate in [True, False]:
41-
for _ in range(10):
42-
num_msgs = random.randint(3, 10)
43-
sub_sock = msgq.sub_sock(sock, conflate=conflate, timeout=None)
44-
zmq_sleep()
41+
num_msgs = random.randint(3, 10)
42+
sub_sock = msgq.sub_sock(sock, conflate=conflate, timeout=None)
43+
zmq_sleep()
4544

46-
sent_msgs = []
47-
for __ in range(num_msgs):
48-
msg = random_bytes()
49-
pub_sock.send(msg)
50-
sent_msgs.append(msg)
51-
time.sleep(0.1)
52-
recvd_msgs = msgq.drain_sock_raw(sub_sock)
53-
if conflate:
54-
assert len(recvd_msgs) == 1
55-
assert recvd_msgs[0] == sent_msgs[-1]
56-
else:
57-
assert len(recvd_msgs) == len(sent_msgs)
58-
for rec_msg, sent_msg in zip(recvd_msgs, sent_msgs):
59-
assert rec_msg == sent_msg
45+
sent_msgs = []
46+
for __ in range(num_msgs):
47+
msg = random_bytes()
48+
pub_sock.send(msg)
49+
sent_msgs.append(msg)
50+
time.sleep(0.1)
51+
recvd_msgs = msgq.drain_sock_raw(sub_sock)
52+
if conflate:
53+
assert len(recvd_msgs) == 1
54+
assert recvd_msgs[0] == sent_msgs[-1]
55+
else:
56+
assert len(recvd_msgs) == len(sent_msgs)
57+
for rec_msg, sent_msg in zip(recvd_msgs, sent_msgs):
58+
assert rec_msg == sent_msg
6059

6160
@pytest.mark.flaky(retries=3, delay=1)
6261
def test_receive_timeout(self):
6362
sock = random_sock()
64-
for _ in range(5):
65-
timeout = random.randrange(200)
66-
sub_sock = msgq.sub_sock(sock, timeout=timeout)
67-
zmq_sleep()
63+
timeout = random.randrange(200)
64+
sub_sock = msgq.sub_sock(sock, timeout=timeout)
65+
zmq_sleep()
6866

69-
start_time = time.monotonic()
70-
recvd = sub_sock.receive()
71-
assert (time.monotonic() - start_time) < (timeout + 0.1)
72-
assert recvd is None
67+
start_time = time.monotonic()
68+
recvd = sub_sock.receive()
69+
assert (time.monotonic() - start_time) < (timeout + 0.1)
70+
assert recvd is None

0 commit comments

Comments
 (0)