Esempio n. 1
0
def test_event_loop_timer_updates():
    callback = _GetCallback()
    event_loop = EventLoop()

    source1 = event_loop.add_timer(_timer_update_callback1, callback)
    source1.timer_update(10)

    source2 = event_loop.add_timer(_timer_update_callback2, callback)
    source2.timer_update(10)

    callback.source1 = source1
    callback.source2 = source2

    assert callback.n_calls == 0

    # Wait 15 ms, so both timers should be called when we dispatch
    time.sleep(0.015)

    # This should take < 1 sec
    start_time = time.time()
    event_loop.dispatch(20)
    end_time = time.time()

    assert callback.n_calls == 2

    assert end_time - start_time < 1
Esempio n. 2
0
def test_event_loop_timer():
    callback = _GetCallback()
    event_loop = EventLoop()

    source = event_loop.add_timer(_timer_callback, callback)
    source.timer_update(10)

    event_loop.dispatch(0)
    assert callback.n_calls == 0

    event_loop.dispatch(20)
    assert callback.n_calls == 1