Skip to content

Commit 70bff9f

Browse files
committed
fix: flaky test_start by waiting for in-flight job re-queue
The in-flight job is re-queued in the worker's CancelledError handler, which stop() only awaits up to cancellation_hard_deadline_s. For the HTTP proxy that re-queue crosses the network, so the new QUEUED status can land just after the worker task returns, causing test_start to read ACTIVE under CI load. Sleep briefly before refreshing.
1 parent a8aa7d9 commit 70bff9f

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

tests/test_worker.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ async def test_start(self, _mock_logger: MagicMock) -> None:
113113
self.assertEqual(job.status, Status.ACTIVE)
114114
task.cancel()
115115
await task
116+
# the in-flight job is re-queued in the worker's CancelledError
117+
# handler, which may land just after the worker task returns
118+
await asyncio.sleep(0.1)
116119
await job.refresh()
117120
self.assertEqual(job.status, Status.QUEUED)
118121

@@ -128,6 +131,7 @@ async def test_start(self, _mock_logger: MagicMock) -> None:
128131
await self.worker.stop()
129132
await asyncio.sleep(0.01)
130133
assert task.done()
134+
await asyncio.sleep(0.1)
131135
await job.refresh()
132136
self.assertEqual(job.status, Status.QUEUED)
133137

0 commit comments

Comments
 (0)