-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass logger to confluent producer and consumer (#1464)
* Pass logger to confluent producer and consumer * Add test to check consumer_logger * Update func signature * Update function signature * User LoggerProto and remove Annotated * Use only logger in signature * Use LoggerProto as type
- Loading branch information
1 parent
d5dce31
commit 1237edb
Showing
8 changed files
with
92 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
dependant | ||
dependant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,4 @@ from faststream.nats import NatsBroker, KvWatch | |
) | ||
async def handler(msg: str): | ||
... | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,4 @@ from faststream.nats import NatsBroker, ObjWatch | |
) | ||
async def handler(filename: str): | ||
... | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import asyncio | ||
import logging | ||
from typing import Any, ClassVar, Dict | ||
|
||
import pytest | ||
|
||
from faststream.broker.core.usecase import BrokerUsecase | ||
from faststream.confluent import KafkaBroker | ||
|
||
|
||
@pytest.mark.confluent() | ||
class TestLogger: | ||
"""A class to represent a test Kafka broker.""" | ||
|
||
timeout: int = 10 | ||
subscriber_kwargs: ClassVar[Dict[str, Any]] = {"auto_offset_reset": "earliest"} | ||
|
||
def get_broker(self, apply_types: bool = False): | ||
return KafkaBroker(apply_types=apply_types) | ||
|
||
def patch_broker(self, broker: BrokerUsecase[Any, Any]) -> BrokerUsecase[Any, Any]: | ||
return broker | ||
|
||
@pytest.mark.asyncio() | ||
async def test_custom_logger( | ||
self, | ||
queue: str, | ||
event: asyncio.Event, | ||
): | ||
test_logger = logging.getLogger("test_logger") | ||
consume_broker = KafkaBroker(logger=test_logger) | ||
|
||
@consume_broker.subscriber(queue, **self.subscriber_kwargs) | ||
def subscriber(m): | ||
event.set() | ||
|
||
async with self.patch_broker(consume_broker) as br: | ||
await br.start() | ||
|
||
for sub in br._subscribers.values(): | ||
consumer_logger = sub.consumer.logger | ||
assert consumer_logger == test_logger | ||
|
||
producer_logger = br._producer._producer.logger | ||
assert producer_logger == test_logger | ||
|
||
await asyncio.wait( | ||
( | ||
asyncio.create_task(br.publish("hello", queue)), | ||
asyncio.create_task(event.wait()), | ||
), | ||
timeout=self.timeout, | ||
) | ||
|
||
assert event.is_set() |