Skip to content

Commit

Permalink
Fixed test warning on the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Oct 2, 2023
1 parent e0ebc68 commit 1aa7b35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 15 additions & 0 deletions ably/executer/eventloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ def create() -> 'AppEventLoop':
app_loop.is_active = True
return app_loop

def run_sync(self, coro):
# todo - can only handle run_sync from different thread than app_loop
# caller_eventloop = None
# try:
# caller_eventloop: events = asyncio.get_running_loop()
# except Exception:
# pass
# Handle calls from app eventloop on the same loop, return awaitable
# if caller_eventloop is not None and caller_eventloop == self.loop:
# task = self.loop.create_task(coro)
# task.add_done_callback

future = asyncio.run_coroutine_threadsafe(coro, self.loop)
return future.result()

def close(self) -> events:
if self.loop is not None and self.loop.is_running():
self.loop.call_soon_threadsafe(self.loop.stop)
Expand Down
9 changes: 5 additions & 4 deletions test/ably/sync/sync_restchannelpublish_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import msgpack
import pytest

from ably import AblyException, IncompatibleClientIdException
from ably import AblyException, IncompatibleClientIdException, AblyRest
from ably import api_version
from ably.rest.auth import Auth
from ably.types.message import Message
Expand Down Expand Up @@ -522,14 +522,14 @@ def test_idempotent_mixed_ids(self):
assert request_body[0]['id'] == 'foobar'
assert 'id' not in request_body[1]

def get_ably_rest(self, *args, **kwargs):
def get_ably_rest(self, *args, **kwargs) -> AblyRest:
kwargs['use_binary_protocol'] = self.use_binary_protocol
return TestAppSync.get_ably_rest(*args, **kwargs)

# RSL1k4
def test_idempotent_library_generated_retry(self):
test_vars = TestAppSync.get_test_vars()
ably = self.get_ably_rest(idempotent_rest_publishing=True, fallback_hosts=[test_vars["host"]] * 3)
ably: AblyRest = self.get_ably_rest(idempotent_rest_publishing=True, fallback_hosts=[test_vars["host"]] * 3)
channel = ably.channels[self.get_channel_name()]

state = {'failures': 0}
Expand All @@ -550,7 +550,8 @@ async def side_effect(*args, **kwargs):
assert state['failures'] == 2
history = channel.history()
assert len(history.items) == 1
client.aclose()

ably.app_loop.run_sync(client.aclose())
ably.close()

# RSL1k5
Expand Down

0 comments on commit 1aa7b35

Please sign in to comment.