def test_multiple_events_built_in_timer(self): # We should test the built-in timer to make sure it's working as # expected. We can also test the hard stop being set to false, (the # event scheduler should execute all remaining events in the queue # before stopping). event_scheduler = EventScheduler(TEST_THREAD) event_scheduler.start() result_list = [] event_scheduler.enter_recurring(1.2, 0, insert_into_list, ('#', result_list)) event_scheduler.enterabs(0.2, 1, insert_into_list, ('A', result_list)) event_scheduler.enterabs(0.4, 1, insert_into_list, ('B', result_list)) event_scheduler.enterabs(0.7, 1, insert_into_list, ('C', result_list)) event_scheduler.enterabs(1, 1, insert_into_list, ('D', result_list)) event_scheduler.stop(False) self.assertListEqual(result_list, ['A', 'B', 'C', 'D', '#'])
def test_multiple_events_different_times(self): event_scheduler = EventScheduler(TEST_THREAD, TestTimer.monotonic, TestTimer) TestTimer.set_event_scheduler(event_scheduler) event_scheduler.start() result_list = [] event_scheduler.enterabs(5, 1, insert_into_list, ('D', result_list)) event_scheduler.enterabs(4, 1, insert_into_list, ('B', result_list)) event_scheduler.enterabs(7, 1, insert_into_list, ('E', result_list)) event_scheduler.enterabs(1, 1, insert_into_list, ('A', result_list)) self.assertListEqual(result_list, []) TestTimer.advance_time(1) self.assertListEqual(result_list, ['A']) TestTimer.advance_time(3) self.assertListEqual(result_list, ['A', 'B']) event_scheduler.enterabs(0.5, 1, insert_into_list, ('C', result_list)) TestTimer.advance_time(1) self.assertListEqual(result_list, ['A', 'B', 'C', 'D']) TestTimer.advance_time(2) self.assertListEqual(result_list, ['A', 'B', 'C', 'D', 'E']) event_scheduler.stop()