Skip to content

Commit

Permalink
Should work
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Dec 5, 2024
1 parent 8e4e711 commit e4f6490
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 1,784 deletions.
16 changes: 12 additions & 4 deletions pubnub/pubnub_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from asyncio import Event, Queue, Semaphore
from yarl import URL
from httpx import AsyncHTTPTransport
from pubnub.event_engine.containers import PresenceStateContainer
from pubnub.event_engine.models import events, states

Expand All @@ -33,6 +34,14 @@
logger = logging.getLogger("pubnub")


class PubNubAsyncHTTPTransport(AsyncHTTPTransport):
is_closed: bool = False

def close(self):
self.is_closed = True
super().aclose()


class PubNubAsyncio(PubNubCore):
"""
PubNub Python SDK for asyncio framework
Expand All @@ -45,10 +54,7 @@ def __init__(self, config, custom_event_loop=None, subscription_manager=None):
self._connector = None
self._session = None

self._connector = httpx.AsyncHTTPTransport()

if not hasattr(self._connector, 'close'):
self._connector.close = self._connector.aclose
self._connector = PubNubAsyncHTTPTransport()

if not subscription_manager:
subscription_manager = EventEngineSubscriptionManager
Expand Down Expand Up @@ -150,6 +156,8 @@ async def _request_helper(self, options_func, cancellation_event):
:param cancellation_event:
:return:
"""
if self._connector and self._connector.is_closed:
raise RuntimeError('Session is closed')
if cancellation_event is not None:
assert isinstance(cancellation_event, Event)

Expand Down
4 changes: 2 additions & 2 deletions tests/integrational/asyncio/test_invocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def test_publish_future_raises_pubnub_error(event_loop):
async def test_publish_future_raises_lower_level_error(event_loop):
pubnub = PubNubAsyncio(corrupted_keys, custom_event_loop=event_loop)

pubnub._connector.aclose()
pubnub._connector.close()

with pytest.raises(RuntimeError) as exinfo:
await pubnub.publish().message('hey').channel('blah').result()
Expand Down Expand Up @@ -102,7 +102,7 @@ async def test_publish_envelope_raises(event_loop):
async def test_publish_envelope_raises_lower_level_error(event_loop):
pubnub = PubNubAsyncio(corrupted_keys, custom_event_loop=event_loop)

pubnub._connector.aclose()
pubnub._connector.close()

e = await pubnub.publish().message('hey').channel('blah').future()
assert isinstance(e, PubNubAsyncioException)
Expand Down
511 changes: 0 additions & 511 deletions tests/integrational/fixtures/asyncio/file_upload/delete_file.yaml

This file was deleted.

This file was deleted.

Loading

0 comments on commit e4f6490

Please sign in to comment.