Exemple #1
0
 def test_emit_std_output_queue_full(self):
     queue = MagicMock()
     with patch("kafkaesk.ext.logging.handler.KafkaeskQueue", return_value=queue), patch(
         "kafkaesk.ext.logging.handler.sys.stderr.write"
     ) as std_write:
         queue.put_nowait.side_effect = asyncio.QueueFull
         handler = PydanticKafkaeskHandler(MagicMock(), "foo")
         record = Mock()
         record.pydantic_data = []
         handler.emit(record)
         std_write.assert_called_once()
Exemple #2
0
 def test_emit_drops_message_on_runtime_error_start(self):
     queue = MagicMock()
     with patch("kafkaesk.ext.logging.handler.KafkaeskQueue", return_value=queue), patch(
         "kafkaesk.ext.logging.handler.sys.stderr.write"
     ) as std_write:
         queue.running = False
         queue.start.side_effect = RuntimeError
         handler = PydanticKafkaeskHandler(MagicMock(), "foo")
         record = Mock()
         record.pydantic_data = []
         handler.emit(record)
         std_write.assert_called_once()
Exemple #3
0
async def test_handler_initializes_applogger(kafka, logger):
    app = kafkaesk.Application(
        [f"{kafka[0]}:{kafka[1]}"],
        topic_prefix=uuid.uuid4().hex,
        kafka_settings={"metadata_max_age_ms": 500},
    )

    handler = PydanticKafkaeskHandler(app, "log.test")
    logger.addHandler(handler)

    logger.error("Hi!")

    await asyncio.sleep(0.1)
    assert app._initialized
Exemple #4
0
def kafakesk_handler(app, logger):
    handler = PydanticKafkaeskHandler(app, "log.test")
    logger.addHandler(handler)

    return handler
Exemple #5
0
 def test_clone(self):
     handler = PydanticKafkaeskHandler(MagicMock(), "foo")
     handler2 = handler.clone()
     assert handler != handler2
     assert handler.app == handler2.app
     assert handler._queue == handler2._queue
Exemple #6
0
def kafakesk_handler(app, logger):
    handler = PydanticKafkaeskHandler(app, "log.test")
    handler.setFormatter(PydanticFormatter())
    logger.addHandler(handler)

    return handler