Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions test/back2back_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,26 +450,27 @@ def test_listen_only_while_recv_blocks(self):
The wrapped bus class has a listen_only property that records when
it is set.
Events:
Block in recv() with a timeout of 0.3 s on another thread, then
Block in recv() with a timeout of 1.0 s on another thread, then
read listen_only and set it to True.
Evaluate:
Reading returns within 0.2 s, while recv() still blocks; setting
reaches the wrapped bus only after 0.25 s, once recv() returned.
Reading takes less than 0.5 s, while recv() still blocks; setting
reaches the wrapped bus only after 0.9 s, once recv() returned.
"""
set_at = []
listen_only = property(lambda _: False, lambda _, value: set_at.append(time()))
receiver = ThreadPool(1)
with patch.object(type(self.bus2.__wrapped__), "listen_only", listen_only):
start = time()
pending = receiver.apply_async(self.bus2.recv, (0.3,))
pending = receiver.apply_async(self.bus2.recv, (1.0,))
sleep(0.1) # let the receiver take the receive lock

read_start = time()
self.assertIs(self.bus2.listen_only, False)
self.assertLess(time() - start, 0.2)
self.assertLess(time() - read_start, 0.5)

self.bus2.listen_only = True
self.assertEqual(len(set_at), 1)
self.assertGreaterEqual(set_at[0] - start, 0.25)
self.assertGreaterEqual(set_at[0] - start, 0.9)

self.assertIsNone(pending.get())
receiver.close()
Expand Down
Loading