async def test_timeout_check_no_bump(timeout_check): await sleep(timeout_check._timeout + Timedelta.from_ms(10)) callback = timeout_check._timeout_callback assert callback.called assert callback.last_timestamp is None assert callback.timeout == timeout_check._timeout
async def test_timeout_check_no_callback_after_cancel(timeout): class CallOnce(Callback): def __init__(self): self.called_before = False super().__init__() def __call__(self, *, timeout, last_timestamp): assert not self.called_before super().__call__(timeout=timeout, last_timestamp=last_timestamp) self.called_before = True timeout_check = TimeoutCheck(timeout=timeout, on_timeout=CallOnce()) timeout_check.start() await sleep(timeout_check._timeout + Timedelta.from_ms(10)) timeout_check.cancel() await sleep(timeout_check._timeout + Timedelta.from_ms(10))
def timeout() -> Timedelta: return Timedelta.from_ms(100)