コード例 #1
0
ファイル: test_f468afef89d1.py プロジェクト: asteven/butter
def test_f468afef89d():
    TEST_PERIOD = 1
    TIMEOUT = TEST_PERIOD * 2
    
    # create a timer
    timer = Timer()

    # set the timer
    timer.offset(seconds=TEST_PERIOD, nano_seconds=TEST_PERIOD)
    timer.repeats(seconds=TEST_PERIOD, nano_seconds=TEST_PERIOD)
    timer.update()

    # ensure it fires
    try:
        timer.wait(TIMEOUT)
    except TimeoutError:
        fail("Timer did not fire")
    
    # drain the event list
    timer.read_event()

    # reset and update the timer
    timer.disable()
    timer.update()

    new_val = timer.get_current()
    assert new_val.next_event == (0, 0), 'Timer offset did not get reset'
    
    with raises(TimeoutError):
        "Timer fired when is should have been disabled"
        timer.wait(TIMEOUT)
コード例 #2
0
def test_f468afef89d():
    TEST_PERIOD = 1
    TIMEOUT = TEST_PERIOD * 2

    # create a timer
    timer = Timer()

    # set the timer
    timer.offset(seconds=TEST_PERIOD, nano_seconds=TEST_PERIOD)
    timer.repeats(seconds=TEST_PERIOD, nano_seconds=TEST_PERIOD)
    timer.update()

    # ensure it fires
    try:
        timer.wait(TIMEOUT)
    except TimeoutError:
        fail("Timer did not fire")

    # drain the event list
    timer.read_event()

    # reset and update the timer
    timer.disable()
    timer.update()

    new_val = timer.get_current()
    assert new_val.next_event == (0, 0), 'Timer offset did not get reset'

    with raises(TimeoutError):
        "Timer fired when is should have been disabled"
        timer.wait(TIMEOUT)
コード例 #3
0
def test_timerfd_intergration():
    "Check and confirm that a 0.5s timer fires roughly every 0.5s as a smoke test"
    INTERVAL = 1
    UPPER_BOUND = INTERVAL * 1.1
    LOWER_BOUND = INTERVAL * 0.9
    DELAY = 0.3
    NANO_SECONDS_TO_SECONDS = 1000000000.0

    t = Timer()
    t.repeats(seconds=INTERVAL).update()

    for i in range(5):
        old_time = time()
        num_events = t.wait()
        new_time = time()

        assert num_events == 1, "Too many events"
        period = new_time - old_time
        assert LOWER_BOUND < period < UPPER_BOUND, "timer fired too late or too early"

    # Wait a bit and ensure that the remaining time on the timerfd gets updated
    sleep(DELAY)
    expected_value = INTERVAL - DELAY

    next_event = t.get_current().next_event
    next_event = next_event.seconds + (next_event.nano_seconds /
                                       NANO_SECONDS_TO_SECONDS)

    LOWER_BOUND = expected_value * 0.9
    UPPER_BOUND = expected_value * 1.1

    assert LOWER_BOUND < next_event < UPPER_BOUND, "current timer does not match what we expect after a (known) time delay"

    t.close()
コード例 #4
0
def test_timerfd_intergration():
    "Check and confirm that a 0.5s timer fires roughly every 0.5s as a smoke test"
    INTERVAL = 1
    UPPER_BOUND = INTERVAL * 1.1
    LOWER_BOUND = INTERVAL * 0.9
    DELAY = 0.3
    NANO_SECONDS_TO_SECONDS = 1000000000.0

    t = Timer()
    t.repeats(seconds=INTERVAL).update()

    for i in range(5):
        old_time = time()
        num_events = t.wait()
        new_time = time()

        assert num_events == 1, "Too many events"
        period = new_time - old_time
        assert LOWER_BOUND < period < UPPER_BOUND, "timer fired too late or too early"

    # Wait a bit and ensure that the remaining time on the timerfd gets updated
    sleep(DELAY)
    expected_value = INTERVAL - DELAY

    next_event = t.get_current().next_event
    next_event = next_event.seconds + (next_event.nano_seconds / NANO_SECONDS_TO_SECONDS)

    LOWER_BOUND = expected_value * 0.9
    UPPER_BOUND = expected_value * 1.1

    assert (
        LOWER_BOUND < next_event < UPPER_BOUND
    ), "current timer does not match what we expect after a (known) time delay"

    t.close()