def test_when_cleanup_throws_it_continues_processing_queue_messages(self, parser, client): class MockImpl(MockAdapter): def cleanup(self): raise Exception('Something bad happened') mock_receive(self.config, client, parser, MockImpl, '{"test": "a"}', None, '{"test": "b"}') self.assertEqual(MockAdapter.messages, [{'test': 'a'}, {'test': 'b'}])
def test_when_the_adapter_runs_without_completing_the_request_it_calls_cleanup_on_the_adapter(self, parser, client): class MockImpl(MockAdapter): def invoke(self): self.is_complete = False mock_receive(self.config, client, parser, MockImpl, '{"test": "a"}') self.assertListEqual(MockImpl.cleaned_up, [True])
def test_when_the_adapter_throws_it_calls_cleanup_on_the_adapter(self, parser, client): class MockImpl(MockAdapter): def invoke(self): self.is_complete = False raise Exception('Something bad happened') mock_receive(self.config, client, parser, MockImpl, '{"test": "a"}', None, '{"test": "b"}') self.assertListEqual(MockImpl.cleaned_up, [True, True])
def test_uses_optional_visibility_timeouts_from_the_command_line(self, parser, client): sqs = mock_receive(self.config, client, parser, MockAdapter) sqs.receive_message.assert_called_with( QueueUrl='test-queue-url', VisibilityTimeout=100, WaitTimeSeconds=20, MaxNumberOfMessages=1) self.assertListEqual(MockAdapter.messages, []) self.assertListEqual(MockAdapter.errors, [])
def test_listens_on_the_provided_queue(self, parser, client): sqs = mock_receive(self.config, client, parser, MockAdapter) sqs.receive_message.assert_called_with( QueueUrl='test-queue-url', VisibilityTimeout=600, WaitTimeSeconds=20, MaxNumberOfMessages=1) self.assertListEqual(MockAdapter.messages, []) self.assertListEqual(MockAdapter.errors, [])
def test_when_reading_from_queue_health_update_happens( self, parser, mock_path, client): all_test_cases = [ # message received ['{"test": "a"}'], # no message received [None], # error receiving message [Exception()] ] for messages in all_test_cases: with self.subTest(messages=messages): try: mock_receive(self.config, client, parser, MockAdapter, *messages) except Exception: pass mock_path.return_value.touch.assert_called()
def test_when_the_adapter_throws_after_completing_the_request_it_deletes_the_queue_message(self, parser, client): class MockImpl(MockAdapter): def invoke(self): self.is_complete = True raise Exception('Something bad happened') sqs = mock_receive(self.config, client, parser, MockImpl, '{"test": "a"}', None, '{"test": "b"}') sqs.delete_message.assert_called_with( QueueUrl='test-queue-url', ReceiptHandle=2) sqs.change_message_visibility.assert_not_called()
def test_when_the_adapter_runs_without_completing_the_request_it_returns_the_message_to_the_queue( self, parser, client ): class MockImpl(MockAdapter): def invoke(self): self.is_complete = False sqs = mock_receive(self.config, client, parser, MockImpl, '{"test": "a"}', None, '{"test": "b"}') sqs.delete_message.assert_not_called() sqs.change_message_visibility.assert_called_with( QueueUrl='test-queue-url', VisibilityTimeout=0, ReceiptHandle=2)
def test_when_the_adapter_throws_before_completing_the_request_it_returns_the_message_to_the_queue( self, parser, client ): class MockImpl(MockAdapter): def invoke(self): self.is_complete = False raise Exception('Something bad happened') sqs = mock_receive(self.config, client, parser, MockImpl, '{"test": "a"}', None, '{"test": "b"}') sqs.delete_message.assert_not_called() sqs.change_message_visibility.assert_called_with( QueueUrl='test-queue-url', VisibilityTimeout=0, ReceiptHandle=2) self.assertListEqual(MockImpl.cleaned_up, [True, True])
def test_when_the_adapter_completes_the_request_it_calls_cleanup_on_the_adapter(self, parser, client): mock_receive(self.config, client, parser, MockAdapter, '{"test": "a"}', None, '{"test": "b"}') self.assertListEqual(MockAdapter.cleaned_up, [True, True])
def test_when_the_adapter_completes_the_request_it_deletes_the_queue_message(self, parser, client): sqs = mock_receive(self.config, client, parser, MockAdapter, '{"test": "a"}', None, '{"test": "b"}') sqs.delete_message.assert_called_with( QueueUrl='test-queue-url', ReceiptHandle=2)
def test_sends_queue_messages_to_the_adapter(self, parser, client): mock_receive(self.config, client, parser, MockAdapter, '{"test": "a"}', None, '{"test": "b"}') self.assertEqual(MockAdapter.messages, [{'test': 'a'}, {'test': 'b'}])