Example #1
0
def test_process_dlq_correctly_remove_outdated_messages_from_dlq(get_msg_sample):
    # Given
    messages = get_msg_sample
    tm = TopicManager()
    tm.add_message(UDPMessage.from_bytes(messages[1]))

    time.sleep(.01)
    new_image = np.array(4 * [4 * 4 * [[0, 0, 0]]])
    im = ImageManager(max_packet_size=64)
    im.refresh_image(new_image)
    new_messages = list(im.get_messages(2))
    tm.add_message(UDPMessage.from_bytes(new_messages[1]))

    # When

    tm.add_message(UDPMessage.from_bytes(new_messages[0]))

    # Then

    assert len(tm.dead_letter_queue) == 0
Example #2
0
def test_topic_exist_return_true_if_asked_topic_exist_else_return_false(get_msg_sample):
    # Given
    messages = get_msg_sample
    tm = TopicManager()
    existing_topic = 1
    non_existing_topic = 2

    # When
    tm.add_message(UDPMessage.from_bytes(messages[0]))
    result1 = tm.topic_exist(existing_topic)
    result2 = tm.topic_exist(non_existing_topic)

    # Then
    assert result1 is True
    assert result2 is False
Example #3
0
def test_from_bytes_returns_none_if_message_is_corrupted():
    # Given
    message_nb = bytes([2, 0])
    payload = bytes([49, 49, 49, 49])
    msg_id = bytes([48, 48, 48, 48])
    topic = bytes([1, 0, 0, 0])

    # When
    msg = UDPMessage(subtopic=message_nb,
                     payload=payload,
                     code=msg_id,
                     topic=topic)
    msg.crc = bytes()
    result = UDPMessage.from_bytes(msg.to_bytes())

    # Then
    assert result is None
Example #4
0
def test_from_bytes_correctly_load_a_message():
    # Given
    message_nb = bytes(UDPMessage.MSG_NUMBER_LENGTH * [1])
    payload = bytes([49, 49, 49, 49])
    msg_id = bytes([48, 48, 48, 48])
    topic = bytes([1, 0, 0, 0])

    # When
    msg = UDPMessage(subtopic=message_nb,
                     payload=payload,
                     code=msg_id,
                     topic=topic)
    result = UDPMessage.from_bytes(msg.to_bytes())

    # Then
    assert result.msg_id == msg_id
    assert result.time_creation == msg.time_creation
    assert result.topic == topic
    assert result.message_nb == message_nb
    assert result.payload == payload
    assert result.crc == msg.crc