1111
1212
1313@pytest .mark .asyncio
14+ @pytest .mark .skip (reason = "Needs to be reworked to use VCR." )
1415async def test_timeout_event_on_broken_heartbeat ():
1516 ch = helper .gen_channel ("heartbeat-test" )
1617
@@ -21,54 +22,54 @@ async def test_timeout_event_on_broken_heartbeat():
2122 listener_config = pnconf_env_copy (uuid = helper .gen_channel ("listener" ), enable_subscribe = True )
2223 pubnub_listener = PubNubAsyncio (listener_config )
2324
24- # - connect to :ch-pnpres
25- callback_presence = SubscribeListener ()
26- pubnub_listener .add_listener (callback_presence )
27- pubnub_listener .subscribe ().channels (ch ).with_presence ().execute ()
28- await callback_presence .wait_for_connect ()
25+ try :
26+ # - connect to :ch-pnpres
27+ callback_presence = SubscribeListener ()
28+ pubnub_listener .add_listener (callback_presence )
29+ pubnub_listener .subscribe ().channels (ch ).with_presence ().execute ()
30+ await callback_presence .wait_for_connect ()
2931
30- envelope = await callback_presence .wait_for_presence_on (ch )
31- assert ch == envelope .channel
32- assert 'join' == envelope .event
33- assert pubnub_listener .uuid == envelope .uuid
32+ envelope = await callback_presence .wait_for_presence_on (ch )
33+ assert ch == envelope .channel
34+ assert 'join' == envelope .event
35+ assert pubnub_listener .uuid == envelope .uuid
3436
35- # # - connect to :ch
36- callback_messages = SubscribeListener ()
37- pubnub .add_listener (callback_messages )
38- pubnub .subscribe ().channels (ch ).execute ()
37+ # # - connect to :ch
38+ callback_messages = SubscribeListener ()
39+ pubnub .add_listener (callback_messages )
40+ pubnub .subscribe ().channels (ch ).execute ()
3941
40- useless_connect_future = asyncio .ensure_future (callback_messages .wait_for_connect ())
41- presence_future = asyncio .ensure_future (callback_presence .wait_for_presence_on (ch ))
42+ useless_connect_future = asyncio .ensure_future (callback_messages .wait_for_connect ())
43+ presence_future = asyncio .ensure_future (callback_presence .wait_for_presence_on (ch ))
4244
43- # - assert join event
44- await asyncio .wait ([useless_connect_future , presence_future ])
45+ # - assert join event
46+ done , pending = await asyncio .wait ([useless_connect_future , presence_future ], return_when = asyncio . ALL_COMPLETED )
4547
46- prs_envelope = presence_future .result ()
48+ prs_envelope = presence_future .result ()
4749
48- assert ch == prs_envelope .channel
49- assert 'join' == prs_envelope .event
50- assert pubnub .uuid == prs_envelope .uuid
51- # - break messenger heartbeat loop
52- pubnub ._subscription_manager ._stop_heartbeat_timer ()
50+ assert ch == prs_envelope .channel
51+ assert 'join' == prs_envelope .event
52+ assert pubnub .uuid == prs_envelope .uuid
53+ # - break messenger heartbeat loop
54+ pubnub ._subscription_manager ._stop_heartbeat_timer ()
5355
54- # wait for one heartbeat call
55- await asyncio .sleep (8 )
56+ # wait for one heartbeat call
57+ await asyncio .sleep (8 )
5658
57- # - assert for timeout
58- envelope = await callback_presence .wait_for_presence_on (ch )
59- assert ch == envelope .channel
60- assert 'timeout' == envelope .event
61- assert pubnub .uuid == envelope .uuid
59+ # - assert for timeout
60+ envelope = await callback_presence .wait_for_presence_on (ch )
61+ assert ch == envelope .channel
62+ assert 'timeout' == envelope .event
63+ assert pubnub .uuid == envelope .uuid
6264
63- pubnub .unsubscribe ().channels (ch ).execute ()
64- if isinstance (pubnub ._subscription_manager , AsyncioSubscriptionManager ):
65+ pubnub .unsubscribe ().channels (ch ).execute ()
6566 await callback_messages .wait_for_disconnect ()
6667
67- # - disconnect from :ch-pnpres
68- pubnub_listener .unsubscribe ().channels (ch ).execute ()
69- if isinstance (pubnub ._subscription_manager , AsyncioSubscriptionManager ):
68+ # - disconnect from :ch-pnpres
69+ pubnub_listener .unsubscribe ().channels (ch ).execute ()
7070 await callback_presence .wait_for_disconnect ()
7171
72- await pubnub .stop ()
73- await pubnub_listener .stop ()
74- await asyncio .sleep (0.5 )
72+ finally :
73+ await pubnub .stop ()
74+ await pubnub_listener .stop ()
75+ await asyncio .sleep (0.5 )
0 commit comments