Ejemplo n.º 1
0
def test_pause_abort():
    ev = asyncio.Event()

    def done():
        print("Done")
        ev.set()

    pid = os.getpid()

    def sim_kill():
        os.kill(pid, signal.SIGINT)

    scan = [Msg('checkpoint'), Msg('wait_for', [ev.wait(), ]), ]
    assert_equal(RE.state, 'idle')
    start = ttime.time()
    loop.call_later(1, sim_kill)
    loop.call_later(2, done)

    RE(scan)
    assert_equal(RE.state, 'paused')
    mid = ttime.time()
    RE.abort()
    assert_equal(RE.state, 'idle')
    stop = ttime.time()

    assert mid - start > 1
    assert stop - start < 2
Ejemplo n.º 2
0
def test_pause_abort():
    ev = asyncio.Event()

    def done():
        print("Done")
        ev.set()

    pid = os.getpid()

    def sim_kill():
        os.kill(pid, signal.SIGINT)

    scan = [Msg('checkpoint'), Msg('wait_for', [ev.wait(), ]), ]
    assert_equal(RE.state, 'idle')
    start = ttime.time()
    loop.call_later(1, sim_kill)
    loop.call_later(2, done)

    RE(scan)
    assert_equal(RE.state, 'paused')
    mid = ttime.time()
    RE.abort()
    assert_equal(RE.state, 'idle')
    stop = ttime.time()

    assert mid - start > 1
    assert stop - start < 2
Ejemplo n.º 3
0
def test_pause_from_outside():
    assert_equal(RE.state, 'idle')

    def local_pause():
        RE.request_pause()

    loop.call_later(1, local_pause)
    RE(checkpoint_forever())
    assert_equal(RE.state, 'paused')

    # Cue up a second pause requests in 2 seconds.
    loop.call_later(2, local_pause)
    RE.resume()
    assert_equal(RE.state, 'paused')

    RE.abort()
    assert_equal(RE.state, 'idle')
Ejemplo n.º 4
0
def test_pause_from_outside():
    assert_equal(RE.state, 'idle')

    def local_pause():
        RE.request_pause()

    loop.call_later(1, local_pause)
    RE(checkpoint_forever())
    assert_equal(RE.state, 'paused')

    # Cue up a second pause requests in 2 seconds.
    loop.call_later(2, local_pause)
    RE.resume()
    assert_equal(RE.state, 'paused')

    RE.abort()
    assert_equal(RE.state, 'idle')
Ejemplo n.º 5
0
def test_suspend():
    ev = asyncio.Event()

    test_list = [
        Msg('open_run'),
        Msg('checkpoint'),
        Msg('sleep', None, .2),
        Msg('set', motor, 5),
        Msg('trigger', det),
        Msg('create'),
        Msg('read', motor),
        Msg('read', det),
        Msg('save'),
        Msg('close_run'),
    ]
    assert_equal(RE.state, 'idle')

    def local_suspend():
        RE.request_suspend(ev.wait())

    def resume_cb():
        ev.set()

    out = []

    def ev_cb(name, ev):
        out.append(ev)

    # trigger the suspend right after the check point
    loop.call_later(.1, local_suspend)
    # wait a second and then resume
    loop.call_later(1, resume_cb)
    # grab the start time
    start = ttime.time()
    # run, this will not return until it is done
    RE(test_list, subs={'event': ev_cb})
    # check to make sure it took long enough
    assert out[0]['time'] - start > 1.1

    assert_equal(RE.state, 'idle')
Ejemplo n.º 6
0
def test_suspend():
    ev = asyncio.Event()

    test_list = [
        Msg('open_run'),
        Msg('checkpoint'),
        Msg('sleep', None, .2),
        Msg('set', motor, 5),
        Msg('trigger', det),
        Msg('create'),
        Msg('read', motor),
        Msg('read', det),
        Msg('save'),
        Msg('close_run'),
    ]
    assert_equal(RE.state, 'idle')

    def local_suspend():
        RE.request_suspend(ev.wait())

    def resume_cb():
        ev.set()

    out = []

    def ev_cb(name, ev):
        out.append(ev)
    # trigger the suspend right after the check point
    loop.call_later(.1, local_suspend)
    # wait a second and then resume
    loop.call_later(1, resume_cb)
    # grab the start time
    start = ttime.time()
    # run, this will not return until it is done
    RE(test_list, subs={'event': ev_cb})
    # check to make sure it took long enough
    assert out[0]['time'] - start > 1.1

    assert_equal(RE.state, 'idle')