refactor: address PR #851 review round 3 (ingest transport)
- LocalTransport.run_consumers increments active_consumer_count per worker (instead of once after the loop) so the count is accurate if a later tg.start() raises mid-pool. - Add LocalTransport.aclose() to explicitly close its owned send/receive stream ends (belt-and-suspenders against unclosed-resource warnings; anyio aclose is idempotent, and by shutdown the scanner is already winding down). Reworded the base IngestTransport.aclose() docstring to point at the overrides. - Inline ingest_transport.producer at the scanner/user_manager call sites, dropping the single-use task_producer alias in both lifespan paths. - Annotate DistributedTransport._producer explicitly as ProcrastinateTaskProducer so the drain() coupling is visible and ty catches drift. - Add a unit test for LocalTransport.aclose() (closes the owned streams, idempotent). Refs: Deck #196 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
2179e9ddb0
commit
c0c52c1b34
@@ -23,6 +23,7 @@ from nextcloud_mcp_server.vector.queue import (
|
||||
SpawnWorker,
|
||||
build_transport,
|
||||
)
|
||||
from nextcloud_mcp_server.vector.scanner import DocumentTask
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
@@ -94,6 +95,25 @@ class TestLocalTransport:
|
||||
assert all(s is not None for s in received_streams)
|
||||
assert len({id(s) for s in received_streams}) == 3
|
||||
|
||||
async def test_aclose_closes_owned_streams_idempotently(self):
|
||||
transport = LocalTransport(max_buffer_size=5)
|
||||
await transport.aclose()
|
||||
|
||||
# The send end is closed → the producer raises rather than silently
|
||||
# dropping (the producer wraps the same stream aclose() closed).
|
||||
with pytest.raises(anyio.ClosedResourceError):
|
||||
await transport.producer.send(
|
||||
DocumentTask(
|
||||
user_id="u",
|
||||
doc_id="1",
|
||||
doc_type="note",
|
||||
operation="index",
|
||||
modified_at=0,
|
||||
)
|
||||
)
|
||||
# Idempotent: closing again is a no-op, not an error.
|
||||
await transport.aclose()
|
||||
|
||||
|
||||
class TestDistributedTransport:
|
||||
async def test_run_consumers_is_noop(self):
|
||||
|
||||
Reference in New Issue
Block a user