@@ -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