Esempio n. 1
0
def test_manager_hooks():
    hooks = create_hooks(['load', 'unload', 'start', 'update', 'stop',
        'job.default.dummy.start', 'job.default.dummy.spawn',
        'job.default.dummy.stop', 'job.default.dummy.exit'])
    emitted = []
    loop = pyuv.Loop.default_loop()
    s = get_server(loop, emitted)
    s.start()
    m = Manager(loop=loop)
    m.start(apps=[WebHooks(hooks)])
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=1)
    m.load(config)
    m.manage("dummy")
    m.scale("dummy", 1)
    m.unload("dummy")

    t = pyuv.Timer(loop)

    def on_stop(manager):
        t.start(lambda h: s.stop(), 0.4, 0.0)

    m.stop(on_stop)

    m.run()
    assert ('load', 'default.dummy') in emitted
    assert ('start', 'default.dummy') in emitted
    assert ('update', 'default.dummy') in emitted
    assert ('stop', 'default.dummy') in emitted
    assert ('unload', 'default.dummy') in emitted
    assert ('job.default.dummy.start', 'default.dummy') in emitted
    assert ('job.default.dummy.spawn', 'default.dummy') in emitted
    assert ('job.default.dummy.stop', 'default.dummy') in emitted
    assert ('job.default.dummy.exit', 'default.dummy') in emitted
Esempio n. 2
0
def test_numprocesses():
    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=4)
    m.load(config)
    state = m._get_locked_state("dummy")

    assert len(state.running) == 4
    state.numprocesses = 0
    assert state.numprocesses == 0

    m.manage("dummy")
    time.sleep(0.2)
    assert len(state.running) == 0
    m.stop()
    m.run()
Esempio n. 3
0
def test_numprocesses():
    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=4)
    m.load(config)
    state = m._get_locked_state("dummy")

    assert len(state.running) == 4
    state.numprocesses = 0
    assert state.numprocesses == 0

    m.manage("dummy")
    time.sleep(0.2)
    assert len(state.running) == 0
    m.stop()
    m.run()
Esempio n. 4
0
def test_manager_hooks():
    hooks = create_hooks([
        'load', 'unload', 'start', 'update', 'stop', 'job.default.dummy.start',
        'job.default.dummy.spawn', 'job.default.dummy.stop',
        'job.default.dummy.exit'
    ])
    emitted = []
    loop = pyuv.Loop.default_loop()
    s = get_server(loop, emitted)
    s.start()
    m = Manager(loop=loop)
    m.start(apps=[WebHooks(hooks)])
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=1)
    m.load(config)
    m.manage("dummy")
    m.scale("dummy", 1)
    m.unload("dummy")

    t = pyuv.Timer(loop)

    def on_stop(manager):
        t.start(lambda h: s.stop(), 0.4, 0.0)

    m.stop(on_stop)

    m.run()
    assert ('load', 'default.dummy') in emitted
    assert ('start', 'default.dummy') in emitted
    assert ('update', 'default.dummy') in emitted
    assert ('stop', 'default.dummy') in emitted
    assert ('unload', 'default.dummy') in emitted
    assert ('job.default.dummy.start', 'default.dummy') in emitted
    assert ('job.default.dummy.spawn', 'default.dummy') in emitted
    assert ('job.default.dummy.stop', 'default.dummy') in emitted
    assert ('job.default.dummy.exit', 'default.dummy') in emitted