Exemplo n.º 1
0
def test_get_runners_periodic_debounce(basic_plugins):
    """It should run periodic functions based on the configured interval."""
    plugins, calls, capture = basic_plugins

    # we should start with a blank timings object
    assert len(plugins['timings'][('periodic plugin', 'periodic_coro')]) == 0

    runners = get_runners(plugins, CoroTypes.Periodic, 'scheduler object')
    assert len(runners) == 1
    asyncio.run(runners[0])
    assert calls == [('scheduler object', {'a': 1})]

    # the timings object should now contain the previous run
    assert len(plugins['timings'][('periodic plugin', 'periodic_coro')]) == 1

    # the next run should be skipped because of the interval
    runners = get_runners(plugins, CoroTypes.Periodic, 'scheduler object')
    assert len(runners) == 0

    # if we remove the interval the next run will not get skipped
    plugins['config']['periodic plugin']['interval'] = 0
    runners = get_runners(plugins, CoroTypes.Periodic, 'scheduler object')
    assert len(runners) == 1
    assert calls[-1] == ('scheduler object', {'a': 1})

    # Clean up coroutines we didn't run
    for coro in runners:
        coro.close()
Exemplo n.º 2
0
def test_get_runners_periodic(basic_plugins):
    """It should return runners for periodic functions."""
    plugins, calls, capture = basic_plugins
    runners = get_runners(plugins, CoroTypes.Periodic, 'scheduler object')
    assert len(runners) == 1
    asyncio.run(runners[0])
    assert calls == [('scheduler object', {'a': 1})]
Exemplo n.º 3
0
def test_get_runners_startup(basic_plugins):
    """IT should return runners for startup functions."""
    plugins, calls, capture = basic_plugins
    runners = get_runners(plugins, CoroTypes.StartUp, 'scheduler object')
    assert len(runners) == 1
    asyncio.run(runners[0])
    assert calls == [('scheduler object', {'b': 2})]
Exemplo n.º 4
0
def test_state(basic_plugins):
    """It should pass the same state object with each function call.

    * Run the same plugin function twice.
    * Ensure that the state object recieved by each call is the same object.

    """
    plugins, calls, capture = basic_plugins
    runners = get_runners(plugins, CoroTypes.StartUp, 'scheduler object')
    assert len(runners) == 1
    asyncio.run(*runners)
    assert len(calls) == 1

    runners = get_runners(plugins, CoroTypes.StartUp, 'scheduler object')
    assert len(runners) == 1
    asyncio.run(*runners)
    assert len(calls) == 2

    (_, state1), (_, state2) = calls
    assert id(state1) == id(state2)