def test_timekeeping():
# probably a good idea to use a real clock for *one* test anyway...
TARGET = 0.1
# give it a few tries in case of random CI server flakiness
for _ in range(4):
real_start = time.monotonic()
with _core.open_cancel_scope() as scope:
scope.deadline = _core.current_time() + TARGET
await sleep_forever()
real_duration = time.monotonic() - real_start
accuracy = real_duration / TARGET
print(accuracy)
# Actual time elapsed should always be >= target time
# (== is possible because time.monotonic on Windows is really low res)
if 1.0 <= accuracy < 2: # pragma: no branch
break
else: # pragma: no cover
assert False
评论列表
文章目录