33import pytest
44
55import pubnub as pn
6- from pubnub .pubnub_asyncio import AsyncioSubscriptionManager , PubNubAsyncio , SubscribeListener
6+ from pubnub .pubnub_asyncio import PubNubAsyncio , SubscribeListener
77from tests import helper
88from tests .helper import pnconf_env_copy
99
@@ -21,54 +21,54 @@ async def test_timeout_event_on_broken_heartbeat():
2121 listener_config = pnconf_env_copy (uuid = helper .gen_channel ("listener" ), enable_subscribe = True )
2222 pubnub_listener = PubNubAsyncio (listener_config )
2323
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 ()
24+ try :
25+ # - connect to :ch-pnpres
26+ callback_presence = SubscribeListener ()
27+ pubnub_listener .add_listener (callback_presence )
28+ pubnub_listener .subscribe ().channels (ch ).with_presence ().execute ()
29+ await callback_presence .wait_for_connect ()
2930
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
31+ envelope = await callback_presence .wait_for_presence_on (ch )
32+ assert ch == envelope .channel
33+ assert 'join' == envelope .event
34+ assert pubnub_listener .uuid == envelope .uuid
3435
35- # # - connect to :ch
36- callback_messages = SubscribeListener ()
37- pubnub .add_listener (callback_messages )
38- pubnub .subscribe ().channels (ch ).execute ()
36+ # # - connect to :ch
37+ callback_messages = SubscribeListener ()
38+ pubnub .add_listener (callback_messages )
39+ pubnub .subscribe ().channels (ch ).execute ()
3940
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 ))
41+ useless_connect_future = asyncio .ensure_future (callback_messages .wait_for_connect ())
42+ presence_future = asyncio .ensure_future (callback_presence .wait_for_presence_on (ch ))
4243
43- # - assert join event
44- await asyncio .wait ([useless_connect_future , presence_future ])
44+ # - assert join event
45+ await asyncio .wait ([useless_connect_future , presence_future ], return_when = asyncio . ALL_COMPLETED )
4546
46- prs_envelope = presence_future .result ()
47+ prs_envelope = presence_future .result ()
4748
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 ()
49+ assert ch == prs_envelope .channel
50+ assert 'join' == prs_envelope .event
51+ assert pubnub .uuid == prs_envelope .uuid
52+ # - break messenger heartbeat loop
53+ pubnub ._subscription_manager ._stop_heartbeat_timer ()
5354
54- # wait for one heartbeat call
55- await asyncio .sleep (8 )
55+ # wait for one heartbeat call
56+ await asyncio .sleep (8 )
5657
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
58+ # - assert for timeout
59+ envelope = await callback_presence .wait_for_presence_on (ch )
60+ assert ch == envelope .channel
61+ assert 'timeout' == envelope .event
62+ assert pubnub .uuid == envelope .uuid
6263
63- pubnub .unsubscribe ().channels (ch ).execute ()
64- if isinstance (pubnub ._subscription_manager , AsyncioSubscriptionManager ):
64+ pubnub .unsubscribe ().channels (ch ).execute ()
6565 await callback_messages .wait_for_disconnect ()
6666
67- # - disconnect from :ch-pnpres
68- pubnub_listener .unsubscribe ().channels (ch ).execute ()
69- if isinstance (pubnub ._subscription_manager , AsyncioSubscriptionManager ):
67+ # - disconnect from :ch-pnpres
68+ pubnub_listener .unsubscribe ().channels (ch ).execute ()
7069 await callback_presence .wait_for_disconnect ()
7170
72- await pubnub .stop ()
73- await pubnub_listener .stop ()
74- await asyncio .sleep (0.5 )
71+ finally :
72+ await pubnub .stop ()
73+ await pubnub_listener .stop ()
74+ await asyncio .sleep (0.5 )
0 commit comments