Skip to content

Consolidate duplicated test doubles in worker proxy tests #244

Description

@conradbzura

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode restructuring without behavior changetestTest coverage or test infrastructure

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions