Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
test: sync Redis subscriptions before publishing in test_topic_isolation (#42674)
LII286ee0571114
diff --git a/api/tests/test_containers_integration_tests/libs/broadcast_channel/redis/test_channel.py b/api/tests/test_containers_integration_tests/libs/broadcast_channel/redis/test_channel.pyindex b3799018cae..8086d52191b 100644--- a/api/tests/test_containers_integration_tests/libs/broadcast_channel/redis/test_channel.py+++ b/api/tests/test_containers_integration_tests/libs/broadcast_channel/redis/test_channel.py@@ -18,7 +18,7 @@ import pytestimport redisfrom testcontainers.redis import RedisContainer-from libs.broadcast_channel.channel import BroadcastChannel, Subscription, Topic+from libs.broadcast_channel.channel import BroadcastChannel, Subscriptionfrom libs.broadcast_channel.exc import SubscriptionClosedErrorfrom libs.broadcast_channel.redis.pubsub_channel import BroadcastChannel as RedisBroadcastChannel@@ -189,37 +189,63 @@ class TestRedisBroadcastChannelIntegration:message1 = b"message for topic1"message2 = b"message for topic2"- # Create producers and subscribers for different topicstopic1 = broadcast_channel.topic(topic1_name)topic2 = broadcast_channel.topic(topic2_name)+ # Subscriptions are created here so they can be closed from the finally block+ # if a future times out, preventing consumers from blocking executor shutdown.+ subscription1 = topic1.subscribe()+ subscription2 = topic2.subscribe()+ ready_event1 = threading.Event()+ ready_event2 = threading.Event()+def producer_thread():- time.sleep(0.1)+ # Wait until both subscriptions are provably active before publishing.+ # Redis Pub/Sub does not replay a message published before SUBSCRIBE is active.+ deadline = time.time() + 5.0+ for ev in (ready_event1, ready_event2):+ remaining = deadline - time.time()+ ev.wait(timeout=max(0.0, remaining))topic1.publish(message1)topic2.publish(message2)- def consumer_by_thread(topic: Topic) -> list[bytes]:- subscription = topic.subscribe()- received = []- with subscription:- for msg in subscription:- received.append(msg)- if len(received) >= 1:- break+ def consumer_by_thread(subscription: Subscription, ready_event: threading.Event) -> list[bytes]:+ received: list[bytes] = []+ # Prime the subscription so the underlying SUBSCRIBE is sent to Redis,+ # then signal readiness before the producer publishes.+ try:+ _ = subscription.receive(0.01)+ except SubscriptionClosedError:+ ready_event.set()+ return received+ ready_event.set()+ while True:+ try:+ msg = subscription.receive(0.1)+ except SubscriptionClosedError:+ break+ if msg is None:+ continue+ received.append(msg)+ if len(received) >= 1:+ breakreturn received- # Run all threadswith ThreadPoolExecutor(max_workers=3) as executor:+ consumer1_future = executor.submit(consumer_by_thread, subscription1, ready_event1)+ consumer2_future = executor.submit(consumer_by_thread, subscription2, ready_event2)producer_future = executor.submit(producer_thread)- consumer1_future = executor.submit(consumer_by_thread, topic1)- consumer2_future = executor.submit(consumer_by_thread, topic2)- # Wait for completion- producer_future.result(timeout=5.0)- received_by_topic1 = consumer1_future.result(timeout=5.0)- received_by_topic2 = consumer2_future.result(timeout=5.0)+ try:+ producer_future.result(timeout=10.0)+ received_by_topic1 = consumer1_future.result(timeout=10.0)+ received_by_topic2 = consumer2_future.result(timeout=10.0)+ finally:+ # Closing here unblocks any consumer still in receive() so the+ # executor can shut down cleanly even when a future timed out.+ subscription1.close()+ subscription2.close()- # Verify topic isolationassert len(received_by_topic1) == 1assert len(received_by_topic2) == 1assert received_by_topic1[0] == message1