Esempio n. 1
0
 def test_celery_task(self, mock_collect):
     """Test celery task to increment prometheus counter."""
     before = REGISTRY.get_sample_value('db_connection_errors_total')
     with mock.patch('django.db.backends.utils.CursorWrapper') as mock_cursor:
         mock_cursor.side_effect = OperationalError('test exception')
         mock_collect.return_value = []
         task = collect_metrics.s().apply()
         self.assertTrue(task.successful())
     after = REGISTRY.get_sample_value('db_connection_errors_total')
     self.assertEqual(1, after - before)
Esempio n. 2
0
 def test_celery_task_no_pushgateway(self, _, __):
     """Test that we handle connection issues gracefully."""
     logging.disable(logging.NOTSET)
     with self.assertLogs(logger="koku.metrics", level=logging.ERROR):
         collect_metrics.s().apply()