Skip to content

Commit d27143b

Browse files
authored
Merge branch 'main' into dependabot/uv/all-dependencies-896e7e6728
2 parents d56daa2 + 2865453 commit d27143b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

tests/instrumentation/test_export.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,21 @@ async def test_task_duration_is_measured(
4141
docket: Docket, worker: Worker, worker_labels: dict[str, str], TASK_DURATION: Mock
4242
):
4343
"""Should record the duration of task execution in the TASK_DURATION histogram."""
44-
45-
# Calibrate: measure actual sleep duration on this platform, since
46-
# asyncio.sleep(0.1) can return early on Windows (~93ms observed)
47-
cal_start = time.monotonic()
48-
await asyncio.sleep(0.1)
49-
calibrated_sleep = time.monotonic() - cal_start
44+
inner_elapsed = 0.0
5045

5146
async def the_task():
47+
nonlocal inner_elapsed
48+
start = time.time()
5249
await asyncio.sleep(0.1)
50+
inner_elapsed = time.time() - start
5351

5452
await docket.add(the_task)()
5553
await worker.run_until_finished()
5654

5755
TASK_DURATION.assert_called_once_with(mock.ANY, worker_labels)
5856
duration: float = TASK_DURATION.call_args.args[0]
5957
assert isinstance(duration, float)
60-
assert calibrated_sleep * 0.8 <= duration <= calibrated_sleep * 3
58+
assert inner_elapsed <= duration <= inner_elapsed * 2
6159

6260

6361
@pytest.fixture

0 commit comments

Comments
 (0)