Пример #1
0
 def test_kafka_connection_metrics_listen_for_messages(
         self, mock_start, mock_sleep):
     """Test check_kafka_connection increments kafka connection errors on KafkaError."""
     connection_errors_before = WORKER_REGISTRY.get_sample_value(
         "kafka_connection_errors_total")
     utils.is_kafka_connected(TEST_HOST, TEST_PORT)
     connection_errors_after = WORKER_REGISTRY.get_sample_value(
         "kafka_connection_errors_total")
     self.assertEqual(connection_errors_after - connection_errors_before, 1)
Пример #2
0
 async def test_listen_for_messages_error(self):
     """Set up the test for raising a kafka error while waiting for messages."""
     # grab the connection error count before
     connection_errors_before = WORKER_REGISTRY.get_sample_value(
         "kafka_connection_errors_total")
     event_loop = asyncio.get_event_loop()
     consumer = msg_handler.AIOKafkaConsumer(loop=event_loop)
     with patch("masu.external.kafka_msg_handler.AIOKafkaConsumer.start",
                side_effect=raise_exception):
         with self.assertRaises(msg_handler.KafkaMsgHandlerError):
             await msg_handler.listen_for_messages(consumer)
         # assert that the error caused the kafka error metric to be incremented
         connection_errors_after = WORKER_REGISTRY.get_sample_value(
             "kafka_connection_errors_total")
         self.assertEqual(
             connection_errors_after - connection_errors_before, 1)
Пример #3
0
 async def test_send_confirmation_error(self):
     """Set up the test for raising a kafka error during sending confirmation."""
     # grab the connection error count before
     connection_errors_before = WORKER_REGISTRY.get_sample_value(
         "kafka_connection_errors_total")
     with patch("masu.external.kafka_msg_handler.AIOKafkaProducer.start",
                side_effect=raise_exception):
         with self.assertRaises(msg_handler.KafkaMsgHandlerError):
             await msg_handler.send_confirmation(
                 request_id="foo",
                 status=msg_handler.SUCCESS_CONFIRM_STATUS)
         # assert that the error caused the kafka error metric to be incremented
         connection_errors_after = WORKER_REGISTRY.get_sample_value(
             "kafka_connection_errors_total")
         self.assertEqual(
             connection_errors_after - connection_errors_before, 1)
Пример #4
0
 def test_send_confirmation_error(self):
     """Set up the test for raising a kafka error during sending confirmation."""
     # grab the connection error count before
     connection_errors_before = WORKER_REGISTRY.get_sample_value(
         "kafka_connection_errors_total")
     with patch("masu.external.kafka_msg_handler.PRODUCER",
                new_callable=Mock()) as mock_producer:
         mock_producer.flush.side_effect = KafkaMsgHandlerError
         with self.assertRaises(msg_handler.KafkaMsgHandlerError):
             msg_handler.send_confirmation(
                 request_id="foo",
                 status=msg_handler.SUCCESS_CONFIRM_STATUS)
         # assert that the error caused the kafka error metric to be incremented
         connection_errors_after = WORKER_REGISTRY.get_sample_value(
             "kafka_connection_errors_total")
         self.assertEqual(
             connection_errors_after - connection_errors_before, 1)
Пример #5
0
 def test_kafka_connection_metrics_listen_for_messages(self, mock_start):
     """Test check_kafka_connection increments kafka connection errors on KafkaError."""
     connection_errors_before = WORKER_REGISTRY.get_sample_value("kafka_connection_errors_total")
     source_integration.check_kafka_connection()
     connection_errors_after = WORKER_REGISTRY.get_sample_value("kafka_connection_errors_total")
     self.assertEqual(connection_errors_after - connection_errors_before, 1)