def test_new_thread_schedule_action_due(self): scheduler = NewThreadScheduler() starttime = default_now() endtime = None def action(scheduler, state): nonlocal endtime endtime = default_now() scheduler.schedule_relative(timedelta(milliseconds=200), action) sleep(0.4) assert endtime is not None diff = endtime - starttime assert diff > timedelta(milliseconds=180)
def test_new_thread_schedule_action_cancel(self): ran = False scheduler = NewThreadScheduler() def action(scheduler, state): nonlocal ran ran = True d = scheduler.schedule_relative(timedelta(milliseconds=1), action) d.dispose() sleep(0.1) assert ran is False