-
Notifications
You must be signed in to change notification settings - Fork 241
fix: patch broker within testbroker context only #1619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Seems like some tests are broken now due new changes |
I saw now, something with patching one of the functions incorrectly. I also added more tests for the |
test: update signature of testclient test in redis
Some tests were, weirdly, still failing. I've checked the subscriber handlers for NATS and Redis and both seem to create multiple listeners for the same queue/topic if I'm guessing this is not intended behavior, because it doesn't seem to happen on the Kafka or Rabbit brokers. I can't seem to get the confluent kafka broker with test Redisfrom faststream.redis import RedisBroker
broker = RedisBroker()
queue = "test_queue"
async def main():
event1 = asyncio.Event()
event2 = asyncio.Event()
@broker.subscriber(queue)
async def m(msg):
if event1.is_set():
event2.set()
else:
event1.set()
await broker.start()
await broker.start()
await broker.publish("hello", queue)
await asyncio.wait(
(
asyncio.create_task(event1.wait()),
asyncio.create_task(event2.wait()),
),
timeout=1,
)
assert event1.is_set() and event2.is_set() is False
if __name__ == "__main__":
import asyncio
asyncio.run(main()) NATSfrom faststream.nats import NatsBroker
broker = NatsBroker()
queue = "test_queue"
async def main():
event1 = asyncio.Event()
event2 = asyncio.Event()
@broker.subscriber(queue)
async def m(msg):
if event1.is_set():
event2.set()
else:
event1.set()
await broker.start()
await broker.start()
await broker.publish("hello", queue)
await asyncio.wait(
(
asyncio.create_task(event1.wait()),
asyncio.create_task(event2.wait()),
),
timeout=1,
)
assert event1.is_set() and event2.is_set() is False
if __name__ == "__main__":
import asyncio
asyncio.run(main()) I'm pushing the changes and you can evaluate if this is the intended behavior, or event just to decide to move it to another PR. |
@sfran96 broker wasn't designed for multiple |
Seems like we can merge it already, tu |
Description
When using a pre-started broker, the broker gets patched only within the context manager, and once it exists the previous connection is still usable.
Fixes #1479
Some of the other changes in the PR are related to using the pre-commit hooks, or not all tests working in < py3.10.
Type of change
Please delete options that are not relevant.
Checklist
scripts/lint.sh
shows no errors)scripts/test-cov.sh
scripts/static-analysis.sh