Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    async def test_send_resend_request_waits_for_target_before_doing_gapfill(
            self, pipeline_with_messages):

        seq_num_app = SeqNumManagerApp(pipeline_with_messages)
        seq_num_app.startup_time = datetime.utcnow() - timedelta(
            seconds=5)  # Don't wait
        assert not seq_num_app.waited_for_resend_request_event.is_set()

        await seq_num_app._send_resend_request([1, 2])

        assert seq_num_app.waited_for_resend_request_event.is_set()
Ejemplo n.º 3
0
    async def test_send_resend_request_sends_resend_request(
            self, pipeline_with_messages):
        seq_num_app = SeqNumManagerApp(pipeline_with_messages)
        seq_num_app.startup_time = datetime.utcnow() - timedelta(
            seconds=5)  # Don't wait

        await seq_num_app._send_resend_request([1, 2])

        # Wait for separate 'send' tasks to complete
        tasks = asyncio.all_tasks()
        await asyncio.wait(tasks, timeout=0.1)

        assert pipeline_with_messages.send.call_count == 1
Ejemplo n.º 4
0
    async def test_handle_seq_num_too_high_starts_buffer_and_sends_resend_request(
            self, pipeline_with_messages, email_message):
        with pytest.raises(StopMessageProcessing):
            seq_num_app = SeqNumManagerApp(pipeline_with_messages)
            seq_num_app.startup_time = datetime.utcnow() - timedelta(
                seconds=5)  # Don't wait

            email_message.MsgSeqNum = 99
            await seq_num_app._handle_sequence_number_too_high(email_message)

        # Wait for separate 'send' tasks to complete
        tasks = asyncio.all_tasks()
        await asyncio.wait(tasks, timeout=0.1)

        assert len(seq_num_app.receive_buffer) == 1
        assert seq_num_app.receive_buffer[0] == email_message
        assert pipeline_with_messages.send.call_count == 1
Ejemplo n.º 5
0
    async def test_handle_seq_num_too_high_buffers_messages_received_out_of_order(
            self, pipeline_with_messages, user_notification_message):
        seq_num_app = SeqNumManagerApp(pipeline_with_messages)
        seq_num_app.startup_time = datetime.utcnow() - timedelta(
            seconds=5)  # Don't wait

        for idx in range(5):
            out_of_sequence_msg = user_notification_message.copy()
            out_of_sequence_msg.MsgSeqNum = 5 + idx
            try:
                await seq_num_app._handle_sequence_number_too_high(
                    out_of_sequence_msg)
            except StopMessageProcessing:
                # Expected
                pass

        # Wait for separate 'send' tasks to complete
        tasks = asyncio.all_tasks()
        await asyncio.wait(tasks, timeout=0.1)

        assert len(seq_num_app.receive_buffer) == 5
        assert pipeline_with_messages.send.call_count == 1