Skip to content

Commit fd3b028

Browse files
committed
chore: review fixes, add test for unordered messages
1 parent 0966233 commit fd3b028

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

ably/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ably.types.options import Options, VCDiffDecoder
99
from ably.util.crypto import CipherParams
1010
from ably.util.exceptions import AblyException, AblyAuthException, IncompatibleClientIdException
11-
from ably.vcdiff.ably_vcdiff_decoder import AblyVCDiffDecoder
11+
from ably.vcdiff.default_vcdiff_decoder import AblyVCDiffDecoder
1212

1313
import logging
1414

ably/types/options.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010

1111
class VCDiffDecoder(ABC):
12+
"""
13+
The VCDiffDecoder class defines the interface for delta decoding operations.
14+
15+
This class serves as an abstract base class for implementing delta decoding
16+
algorithms, which are used to generate target bytes from compressed delta
17+
bytes and base bytes. Subclasses of this class should implement the decode
18+
method to handle the specifics of delta decoding. The decode method typically
19+
takes a delta bytes and base bytes as input and returns the decoded output.
20+
21+
"""
1222
@abstractmethod
1323
def decode(self, delta: bytes, base: bytes) -> bytes:
1424
pass
File renamed without changes.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ per-file-ignores =
88
# imported but unused
99
__init__.py: F401
1010
# Exclude virtual environment check
11-
exclude = .venv,venv,env,.env,.git,__pycache__,.pytest_cache,build,dist,*.egg-info
11+
exclude = .venv,venv,env,.env,.git,__pycache__,.pytest_cache,build,dist,*.egg-info,ably/sync,test/ably/sync
1212

1313
[tool:pytest]
1414
#log_level = DEBUG

test/ably/realtime/realtimechannel_vcdiff_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,44 @@ def on_message(message):
182182
assert expected_message == actual_message, f"Check message.data for message {expected_message}"
183183
finally:
184184
await ably.close()
185+
186+
async def test_delta_message_out_of_order(self):
187+
test_vcdiff_decoder = MockVCDiffDecoder()
188+
ably = await TestApp.get_ably_realtime(vcdiff_decoder=test_vcdiff_decoder)
189+
190+
try:
191+
await asyncio.wait_for(ably.connection.once_async(ConnectionState.CONNECTED), timeout=5)
192+
channel = ably.channels.get('delta_plugin_out_of_order', ChannelOptions(params={'delta': 'vcdiff'}))
193+
await channel.attach()
194+
message_waiters = [WaitableEvent(), WaitableEvent()]
195+
messages_received = []
196+
counter = 0
197+
198+
def on_message(message):
199+
nonlocal counter
200+
messages_received.append(message.data)
201+
message_waiters[counter].finish()
202+
counter += 1
203+
204+
await channel.subscribe(on_message)
205+
await channel.publish("1", self.test_data[0])
206+
await message_waiters[0].wait(timeout=30)
207+
208+
attaching_reason = None
209+
210+
def on_attaching(state_change):
211+
nonlocal attaching_reason
212+
attaching_reason = state_change.reason
213+
214+
channel.on('attaching', on_attaching)
215+
216+
object.__getattribute__(channel, '_RealtimeChannel__decoding_context').last_message_id = 'fake_id'
217+
await channel.publish("2", self.test_data[1])
218+
await message_waiters[1].wait(timeout=30)
219+
assert test_vcdiff_decoder.number_of_calls == 0, "Check that no delta message was decoded"
220+
assert self._equals(messages_received[0], self.test_data[0]), "Check message.data for message 1"
221+
assert self._equals(messages_received[1], self.test_data[1]), "Check message.data for message 2"
222+
assert attaching_reason.code == 40018, "Check error code passed through per RTL18c"
223+
224+
finally:
225+
await ably.close()

0 commit comments

Comments
 (0)