Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/realtime/src/realtime/_async/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def start_timeout(self):

async def timeout(self):
await asyncio.sleep(self.timeout)
self.timeout_task = None
self.trigger(RealtimeAcknowledgementStatus.Timeout, {})
if self.ref and self.ref in self.channel.messages_waiting_for_ack:
del self.channel.messages_waiting_for_ack[self.ref]
Expand Down
37 changes: 37 additions & 0 deletions src/realtime/tests/test_push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from unittest.mock import AsyncMock, Mock

import pytest

from realtime._async.push import AsyncPush
from realtime.types import RealtimeAcknowledgementStatus


@pytest.mark.asyncio
async def test_resend_starts_a_new_timeout():
channel = Mock()
channel.topic = "realtime:test"
channel.join_push.ref = "join-ref"
channel.messages_waiting_for_ack = {}
channel.socket._make_ref.side_effect = ["1", "2"]
channel.socket.send = AsyncMock()

timeout_count = 0

def on_timeout():
nonlocal timeout_count
timeout_count += 1

push = AsyncPush(channel, "broadcast", timeout=0)
push.receive(RealtimeAcknowledgementStatus.Timeout, on_timeout)

await push.send()
first_timeout = push.timeout_task
assert first_timeout is not None
await first_timeout

await push.resend()
second_timeout = push.timeout_task
assert second_timeout is not None
await second_timeout

assert timeout_count == 2