Пример #1
0
def test_user_provided_timeout():

    drain()

    send_message = "hello"
    work_time = 2.0

    qp = SQSPollAccess(test_awsimple_str,
                       visibility_timeout=round(10.0 * work_time),
                       immediate_delete=False,
                       profile_name=test_awsimple_str)
    qp.create_queue()
    qp.send(send_message)
    time.sleep(1.0)
    receive_message = qp.receive_message()
    assert receive_message.message == send_message

    q = SQSAccess(test_awsimple_str, profile_name=test_awsimple_str)
    q.create_queue()
    assert q.receive_message(
    ) is None  # make sure the message is now invisible

    if not is_mock():
        receive_message.delete()  # not working for mock todo: fix

    assert q.receive_message() is None
Пример #2
0
def test_sns_publish():

    drain()

    sqs_access = SQSPollAccess(
        test_awsimple_str
    )  # queue that will subscribe to this topic and we'll read from at the end to test the propagation from SNS to SQS
    sqs_access.create_queue()
    sns_access = SNSAccess(test_awsimple_str)  # our test SNS topic

    sns_access.create_topic(
    )  # this can set the permissions, which can take a while to propagate so it might fail the first time through

    subscription_arn = sns_access.subscribe(
        sqs_access)  # subscribe the SQS queue to the SNS topic
    print(f"{subscription_arn=}")

    # put in your actual email and run this at least once:
    # sns_access.subscribe("*****@*****.**")

    message_string = "This is a test for awsimple."
    subject_string = "awsimple test"
    message_id = sns_access.publish(message_string, subject_string)
    print(f"{message_id=}")
    assert message_id is not None and len(message_id) > 0

    message = json.loads(sqs_access.receive_message().message)
    returned_message_string = message["Message"]
    print(f"{returned_message_string=}")
    assert returned_message_string == message_string
Пример #3
0
def test_actually_timeout():

    drain()

    send_message = "hello"
    work_time = 5.0

    qp = SQSPollAccess(test_awsimple_str,
                       visibility_timeout=round(0.5 * work_time),
                       immediate_delete=False,
                       profile_name=test_awsimple_str)
    qp.create_queue()
    qp.send(send_message)
    time.sleep(1.0)
    receive_message = qp.receive_message()
    assert receive_message.message == send_message  # got it once

    q = SQSAccess(test_awsimple_str, profile_name=test_awsimple_str)
    assert q.receive_message(
    ) is None  # make sure the message is now invisible
    time.sleep(
        work_time
    )  # will take "too long", so message should be available again on next receive_message

    if not is_mock():
        # not working for mock todo: fix
        assert qp.receive_message().message == send_message
        receive_message.delete()  # now we delete it

    assert q.receive_message() is None
def test_sqs_receive_nothing_poll_many():
    drain()
    start = time.time()
    queue = SQSPollAccess(test_awsimple_str)  # will return in AWS SQS max wait time (e.g. 20 sec)
    queue.create_queue()
    assert len(queue.receive_messages()) == 0

    t = time.time() - start
    print(f"{t=}")
    assert math.isclose(t, aws_sqs_long_poll_max_wait_time + margin, rel_tol=rel_tol, abs_tol=margin)
Пример #5
0
def test_user_provided_timeout_nonsensical_parameters():

    drain()

    send_message = "hello"
    work_time = 2.0

    q = SQSPollAccess(test_awsimple_str,
                      visibility_timeout=round(10.0 * work_time),
                      profile_name=test_awsimple_str)
    q.create_queue()
    q.send(send_message)
    with pytest.raises(ValueError):
        q.receive_message()
Пример #6
0
def test_sqs_poll_immediate_delete():

    drain()

    q = SQSPollAccess(test_awsimple_str, profile_name=test_awsimple_str)
    q.create_queue()

    send_time = time.time()
    q.send(send_message)

    receive_message = q.receive_message(
    )  # will long poll so we expect the message to be available within one call
    assert receive_message is not None
    print(receive_message)
    assert receive_message.message == send_message
    print(f"took {time.time() - send_time} seconds")
Пример #7
0
    queue.max_history = 5  # test that we can delete old history values by using a very small history
    for value in range(0, queue.max_history):
        print(value)
        queue.send(str(value))
    while len(messages := queue.receive_messages()) > 0:
        time.sleep(work_time)
        pprint(messages)
        for m in messages:
            print(f"deleting {m.message}")
            m.delete()

    # now do a long poll style
    poll_queue = SQSPollAccess(test_awsimple_str,
                               immediate_delete=False,
                               profile_name=test_awsimple_str)
    poll_queue.create_queue()

    print("sending test message")
    send_time = time.time()
    poll_queue.send(send_message)

    receive_message = poll_queue.receive_message(
    )  # will long poll so we expect the message to be available within one call
    assert receive_message is not None
    print(receive_message.message)
    assert receive_message.message == send_message
    time.sleep(work_time)  # do some work
    print(f"took {time.time() - send_time} seconds")
    receive_message.delete()

    nominal_work_time = poll_queue.calculate_nominal_work_time()