test(client): tighten polling test synchronization

This commit is contained in:
QiuSW
2026-08-05 12:47:34 +08:00
parent ae4b9ef08b
commit b4ff9096c3
2 changed files with 11 additions and 5 deletions
+6 -4
View File
@@ -134,8 +134,10 @@ class FakeConsumer:
def wait_until(predicate, timeout_ms: int = 2000) -> None:
elapsed = 0
while not predicate() and elapsed < timeout_ms:
QTest.qWait(10)
elapsed += 10
# worker 仍通过真实 Qt 队列信号推进,因此测试必须持续处理事件;
# 1 ms 量子既会让出 QThread,又不会把每次状态转换放大成 10 ms 等待。
QTest.qWait(1)
elapsed += 1
if not predicate():
raise AssertionError("condition_not_reached")
@@ -199,7 +201,6 @@ class PollingCoordinatorTests(unittest.TestCase):
gateway = FakeGateway()
coordinator, frozen = self.make_coordinator(store, gateway, None)
coordinator.start()
QTest.qWait(20)
self.assertEqual(coordinator.state, PollingState.BLOCKED)
self.assertIn("尚未接入", coordinator.reason)
self.assertEqual(store.start_calls, 0)
@@ -316,8 +317,9 @@ class PollingCoordinatorTests(unittest.TestCase):
coordinator.configuration_freeze_changed.connect(freeze_events.append)
coordinator.start()
wait_until(lambda: coordinator.state == PollingState.BLOCKED and not coordinator.operation_in_flight)
QTest.qWait(30)
self.assertEqual(gateway.calls, 1)
self.assertFalse(coordinator._timer.isActive())
self.assertIsNone(coordinator._scheduled_epoch)
self.assertFalse(store.current.session.accept_new)
self.assertEqual(freeze_events[-1], expected_frozen)