Skip to content

Commit b8bdce5

Browse files
committedJun 3, 2015
sync_struct test: don't poll, use Event instead
1 parent 21d88d8 commit b8bdce5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
 

Diff for: ‎artiq/test/sync_struct.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ def init_test_dict(self, init):
2929
self.test_dict = init
3030
return init
3131

32-
@asyncio.coroutine
33-
def do_recv(self):
34-
while not hasattr(self, "test_dict")\
35-
or "Finished" not in self.test_dict.keys():
36-
yield from asyncio.sleep(0.5)
32+
def notify(self, mod):
33+
print("mod: {}".format(mod))
34+
if (mod["action"] == "init" and "Finished" in mod["struct"])\
35+
or (mod["action"] == "setitem" and mod["key"] == "Finished"):
36+
self.receiving_done.set()
3737

3838
def setUp(self):
3939
self.loop = asyncio.new_event_loop()
4040
asyncio.set_event_loop(self.loop)
4141

4242
def test_recv(self):
4343
loop = self.loop
44+
self.receiving_done = asyncio.Event()
4445
publisher = asyncio.Future()
4546
test_dict = asyncio.Future()
4647
asyncio.async(start_server(publisher, test_dict))
@@ -53,10 +54,11 @@ def test_recv(self):
5354
loop.run_until_complete(write_test_data(test_vector))
5455

5556
asyncio.async(write_test_data(test_dict))
56-
self.subscriber = sync_struct.Subscriber("test", self.init_test_dict)
57+
self.subscriber = sync_struct.Subscriber("test", self.init_test_dict,
58+
self.notify)
5759
loop.run_until_complete(self.subscriber.connect(test_address,
5860
test_port))
59-
loop.run_until_complete(self.do_recv())
61+
loop.run_until_complete(self.receiving_done.wait())
6062
self.assertEqual(self.test_dict, test_vector)
6163
self.loop.run_until_complete(self.subscriber.close())
6264
self.loop.run_until_complete(self.publisher.stop())

0 commit comments

Comments
 (0)
Please sign in to comment.