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
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_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()
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")
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() print(f"{work_time=}, calculated {nominal_work_time=}") assert math.isclose(nominal_work_time, work_time, rel_tol=0.5, abs_tol=1.0) # fairly wide tolerance