test(client): remove polling stop race

This commit is contained in:
QiuSW
2026-08-05 09:14:02 +08:00
parent 870e5f861d
commit c9b39a4e05
+7 -2
View File
@@ -106,12 +106,15 @@ class FakeGateway:
def __init__(self, outcomes: list[object] | None = None, gate: threading.Event | None = None) -> None:
self.outcomes = list(outcomes or [None])
self.gate = gate
self.entered = threading.Event()
self.calls = 0
def claim_next(self, profile_id: str):
self.calls += 1
self.entered.set()
if self.gate is not None:
self.gate.wait(2)
if not self.gate.wait(5):
raise RuntimeError("test_gateway_release_timeout")
outcome = self.outcomes.pop(0) if self.outcomes else None
if isinstance(outcome, Exception):
raise outcome
@@ -251,7 +254,9 @@ class PollingCoordinatorTests(unittest.TestCase):
visible: list[object] = []
coordinator.claim_visible.connect(visible.append)
coordinator.start()
wait_until(lambda: coordinator.state == PollingState.CLAIMING)
# CLAIMING 状态先于 queued worker 实际进入 claim_next;必须等待
# worker 入口,避免与 FakeGateway 的超时边界竞争而产生套件级偶发失败。
wait_until(lambda: coordinator.state == PollingState.CLAIMING and gateway.entered.is_set())
coordinator._begin_claim(coordinator._epoch)
self.assertEqual(gateway.calls, 1)
coordinator.stop()