@@ -29,18 +29,19 @@ def init_test_dict(self, init):
29
29
self .test_dict = init
30
30
return init
31
31
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 ( )
37
37
38
38
def setUp (self ):
39
39
self .loop = asyncio .new_event_loop ()
40
40
asyncio .set_event_loop (self .loop )
41
41
42
42
def test_recv (self ):
43
43
loop = self .loop
44
+ self .receiving_done = asyncio .Event ()
44
45
publisher = asyncio .Future ()
45
46
test_dict = asyncio .Future ()
46
47
asyncio .async (start_server (publisher , test_dict ))
@@ -53,10 +54,11 @@ def test_recv(self):
53
54
loop .run_until_complete (write_test_data (test_vector ))
54
55
55
56
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 )
57
59
loop .run_until_complete (self .subscriber .connect (test_address ,
58
60
test_port ))
59
- loop .run_until_complete (self .do_recv ())
61
+ loop .run_until_complete (self .receiving_done . wait ())
60
62
self .assertEqual (self .test_dict , test_vector )
61
63
self .loop .run_until_complete (self .subscriber .close ())
62
64
self .loop .run_until_complete (self .publisher .stop ())
0 commit comments