async def test_on_receive_handles_gapfill( self, pipeline_with_messages, user_notification_message ): seq_num_app = SeqNumManagerApp(pipeline_with_messages) seq_num_app.startup_time = datetime.utcnow() - timedelta( seconds=10 ) # Don't wait for resend requests seq_num_app.receive_seq_num = 5 # 5 Messages received so far user_notification_message.seq_num = 8 # Simulate missing messages 6 and 7 try: await seq_num_app.on_receive(user_notification_message) assert pipeline_with_messages.send.call_count == 1 # Resend request sent except StopMessageProcessing: # Expected pass # Simulate resend of 6 and 7 for seq_num in [6, 7]: message = user_notification_message.copy() message.seq_num = seq_num message.PossDupFlag = True await seq_num_app.on_receive(message) # Wait for separate 'send' tasks to complete tasks = asyncio.all_tasks() await asyncio.wait(tasks, timeout=0.1) assert ( pipeline_with_messages.receive.call_count == 1 ) # One queued message (with sequence number 8) processed
def test_handle_sequence_number_too_low_raises_exception_if_number_too_low( self, email_message): with pytest.raises(SessionError): pipeline_mock = MagicMock(BasePipeline) seq_num_app = SeqNumManagerApp(pipeline_mock) seq_num_app.receive_seq_num = 10 email_message.MsgSeqNum = 1 seq_num_app._handle_sequence_number_too_low(email_message)
def test_handle_sequence_number_too_low_skips_duplicates_with_low_sequence_numbers( self, email_message): with pytest.raises(StopMessageProcessing): pipeline_mock = MagicMock(BasePipeline) seq_num_app = SeqNumManagerApp(pipeline_mock) seq_num_app.receive_seq_num = 10 email_message.MsgSeqNum = 1 email_message.PossDupFlag = True seq_num_app._handle_sequence_number_too_low(email_message)