def test_nack_with_visibility_timeout(): """ Consumer delegates to SQS client with visibility timeout """ visibility_timeout_seconds = 2 def loader(metadata): return dict( sqs_consumer=dict( sqs_queue_url=FOO_QUEUE_URL, visibility_timeout_seconds=visibility_timeout_seconds, ), pubsub_message_codecs=dict(default=FooSchema, ), ) graph = create_object_graph("example", testing=True, loader=loader) message = SQSMessage( consumer=graph.sqs_consumer, content=None, media_type=FooSchema.MEDIA_TYPE, message_id=MESSAGE_ID, receipt_handle=RECEIPT_HANDLE, ) message.nack() graph.sqs_consumer.sqs_client.change_message_visibility.assert_called_with( QueueUrl='foo-queue-url', ReceiptHandle=RECEIPT_HANDLE, VisibilityTimeout=visibility_timeout_seconds, )
def test_nack_without_visibility_timeout(): """ Consumer passes """ graph = ExampleDaemon.create_for_testing().graph message = SQSMessage( consumer=graph.sqs_consumer, content=None, media_type=DerivedSchema.MEDIA_TYPE, message_id=MESSAGE_ID, receipt_handle=RECEIPT_HANDLE, ) message.nack() graph.sqs_consumer.sqs_client.change_message_visibility.assert_not_called()
def test_nack_with_visibility_timeout(): """ Consumer delegates to SQS client with visibility timeout """ visibility_timeout_seconds = 2 graph = ExampleDaemon.create_for_testing().graph message = SQSMessage( consumer=graph.sqs_consumer, content=None, media_type=DerivedSchema.MEDIA_TYPE, message_id=MESSAGE_ID, receipt_handle=RECEIPT_HANDLE, ) with patch.object(graph.sqs_consumer.backoff_policy, "visibility_timeout_seconds", visibility_timeout_seconds): message.nack() graph.sqs_consumer.sqs_client.change_message_visibility.assert_called_with( QueueUrl="queue", ReceiptHandle=RECEIPT_HANDLE, VisibilityTimeout=visibility_timeout_seconds, )