mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 00:16:23 +02:00
Subscriber resilience and RabbitMQ fixes (#765)
Subscriber resilience: recreate consumer after connection failure - Move consumer creation from Subscriber.start() into the run() loop, matching the pattern used by Consumer. If the connection drops and the consumer is closed in the finally block, the loop now recreates it on the next iteration instead of spinning forever on a None consumer. Consumer thread safety: - Dedicated ThreadPoolExecutor per consumer so all pika operations (create, receive, acknowledge, negative_acknowledge) run on the same thread — pika BlockingConnection is not thread-safe - Applies to both Consumer and Subscriber classes Config handler type audit — fix four mismatched type registrations: - librarian: was ["librarian"] (non-existent type), now ["flow", "active-flow"] (matches config["flow"] that the handler reads) - cores/service: was ["kg-core"], now ["flow"] (reads config["flow"]) - metering/counter: was ["token-costs"], now ["token-cost"] (singular) - agent/mcp_tool: was ["mcp-tool"], now ["mcp"] (reads config["mcp"]) Update tests
This commit is contained in:
parent
ddd4bd7790
commit
c20e6540ec
9 changed files with 96 additions and 66 deletions
|
|
@ -61,23 +61,21 @@ async def test_subscriber_deferred_acknowledgment_success():
|
|||
max_size=10,
|
||||
backpressure_strategy="block"
|
||||
)
|
||||
|
||||
# Start subscriber to initialize consumer
|
||||
await subscriber.start()
|
||||
|
||||
subscriber.consumer = mock_consumer
|
||||
|
||||
# Create queue for subscription
|
||||
queue = await subscriber.subscribe("test-queue")
|
||||
|
||||
|
||||
# Create mock message with matching queue name
|
||||
msg = create_mock_message("test-queue", {"data": "test"})
|
||||
|
||||
|
||||
# Process message
|
||||
await subscriber._process_message(msg)
|
||||
|
||||
|
||||
# Should acknowledge successful delivery
|
||||
mock_consumer.acknowledge.assert_called_once_with(msg)
|
||||
mock_consumer.negative_acknowledge.assert_not_called()
|
||||
|
||||
|
||||
# Message should be in queue
|
||||
assert not queue.empty()
|
||||
received_msg = await queue.get()
|
||||
|
|
@ -108,9 +106,7 @@ async def test_subscriber_dropped_message_still_acks():
|
|||
max_size=1, # Very small queue
|
||||
backpressure_strategy="drop_new"
|
||||
)
|
||||
|
||||
# Start subscriber to initialize consumer
|
||||
await subscriber.start()
|
||||
subscriber.consumer = mock_consumer
|
||||
|
||||
# Create queue and fill it
|
||||
queue = await subscriber.subscribe("test-queue")
|
||||
|
|
@ -151,9 +147,7 @@ async def test_subscriber_orphaned_message_acks():
|
|||
max_size=10,
|
||||
backpressure_strategy="block"
|
||||
)
|
||||
|
||||
# Start subscriber to initialize consumer
|
||||
await subscriber.start()
|
||||
subscriber.consumer = mock_consumer
|
||||
|
||||
# Don't create any queues - message will be orphaned
|
||||
# This simulates a response arriving after the waiter has unsubscribed
|
||||
|
|
@ -189,9 +183,7 @@ async def test_subscriber_backpressure_strategies():
|
|||
max_size=2,
|
||||
backpressure_strategy="drop_oldest"
|
||||
)
|
||||
|
||||
# Start subscriber to initialize consumer
|
||||
await subscriber.start()
|
||||
subscriber.consumer = mock_consumer
|
||||
|
||||
queue = await subscriber.subscribe("test-queue")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue