Description
tests/runtime/worker/test_proxy.py defines the same test doubles inline across many quorum/dispatch tests. The StubLoadBalancer class — a dispatched flag plus an async def dispatch(self, task, *, context, timeout=None) that records the call — is copy-pasted verbatim in at least four tests (around lines 2007, 2077, 2473, 2758). Alongside it, several near-identical gated async-iterator discovery stubs exist independently: EmptyDiscovery (blocks forever), GatedDiscovery (emits behind an asyncio.Event), and RecoverableDiscovery (emits one worker once a gate opens, then idles).
Hoist a single shared, module-level dispatch-recording stub load balancer and one parameterizable gated-discovery helper (configurable by the events to emit and whether it idles or stops afterward), then migrate the existing call sites to use them. The reusable mock_discovery_service fixture is publisher/lifecycle-shaped (start() / inject_worker_added) and is not a drop-in for the plain gated-subscriber semantics these tests need, so the new helper should target the subscriber shape directly.
Motivation
These parallel near-duplicates violate the code-as-liability precept (refactor in place before copying) and drift independently over time — e.g. one StubLoadBalancer variant could gain a behavior the others lack, or a copy could fall out of step with the real LoadBalancerLike.dispatch signature, silently weakening the tests. Surfaced during the review of PR #243 (issue #238), which added another copy following the existing pattern rather than introducing it.
Expected Outcome
- A single module-level dispatch-recording stub load balancer replaces the inline
StubLoadBalancer copies.
- A single parameterizable gated-discovery helper replaces the bespoke
EmptyDiscovery / GatedDiscovery / RecoverableDiscovery stubs.
- All affected quorum/dispatch tests use the shared helpers, with no behavior change and the full suite still green.
Description
tests/runtime/worker/test_proxy.pydefines the same test doubles inline across many quorum/dispatch tests. TheStubLoadBalancerclass — adispatchedflag plus anasync def dispatch(self, task, *, context, timeout=None)that records the call — is copy-pasted verbatim in at least four tests (around lines 2007, 2077, 2473, 2758). Alongside it, several near-identical gated async-iterator discovery stubs exist independently:EmptyDiscovery(blocks forever),GatedDiscovery(emits behind anasyncio.Event), andRecoverableDiscovery(emits one worker once a gate opens, then idles).Hoist a single shared, module-level dispatch-recording stub load balancer and one parameterizable gated-discovery helper (configurable by the events to emit and whether it idles or stops afterward), then migrate the existing call sites to use them. The reusable
mock_discovery_servicefixture is publisher/lifecycle-shaped (start()/inject_worker_added) and is not a drop-in for the plain gated-subscriber semantics these tests need, so the new helper should target the subscriber shape directly.Motivation
These parallel near-duplicates violate the code-as-liability precept (refactor in place before copying) and drift independently over time — e.g. one
StubLoadBalancervariant could gain a behavior the others lack, or a copy could fall out of step with the realLoadBalancerLike.dispatchsignature, silently weakening the tests. Surfaced during the review of PR #243 (issue #238), which added another copy following the existing pattern rather than introducing it.Expected Outcome
StubLoadBalancercopies.EmptyDiscovery/GatedDiscovery/RecoverableDiscoverystubs.