Beispiel #1
0
def test_stats():
    m = Manager()
    monitored = []

    def cb(info):
        monitored.append(info)

    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("a", cmd, args=args, cwd=wdir)
    m.load(config)
    os_pid = m.running[1].os_pid

    chan = m.subscribe("STATS:default.a")
    chan.bind(cb)

    def stop(handle):
        chan.unbind(cb)
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.3, 0.0)

    m.run()
    assert len(monitored) >= 1
    res = monitored[0]
    assert "cpu" in res
    assert res["os_pid"] == os_pid
Beispiel #2
0
def test_process_events():
    emitted = []
    m = Manager()
    m.start()

    def cb(ev, *args):
        emitted.append(ev)

    # subscribe to all events
    chan = m.subscribe("JOB:default.dummy")
    chan.bind_all(cb)

    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir)
    m.load(config)
    m.unload(config)

    time.sleep(0.2)
    m.stop()
    m.run()

    assert 'start' in emitted
    assert 'spawn' in emitted
    assert 'stop' in emitted
    assert 'exit' in emitted
Beispiel #3
0
def test_basic():
    emitted = []
    m = Manager()
    m.start()

    def cb(ev, msg):
        emitted.append((ev, msg['name']))

    # subscribe to all events
    chan = m.subscribe("EVENTS")
    chan.bind('.', cb)

    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=4)
    m.load(config)
    m.scale("dummy", 1)
    m.unload("dummy")

    time.sleep(0.2)
    m.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
Beispiel #4
0
def test_stats():
    m = Manager()
    monitored = []
    def cb(info):
        monitored.append(info)

    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("a", cmd, args=args, cwd=wdir)
    m.load(config)
    os_pid = m.running[1].os_pid

    chan = m.subscribe("STATS:default.a")
    chan.bind(cb)

    def stop(handle):
        chan.unbind(cb)
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.3, 0.0)

    m.run()
    assert len(monitored) >= 1
    res = monitored[0]
    assert "cpu" in res
    assert res["os_pid"] == os_pid
Beispiel #5
0
def test_process_events():
    emitted = []
    m = Manager()
    m.start()

    def cb(ev, *args):
        emitted.append(ev)

    # subscribe to all events
    chan = m.subscribe("JOB:default.dummy")
    chan.bind_all(cb)

    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir)
    m.load(config)
    m.unload(config)

    time.sleep(0.2)
    m.stop()
    m.run()

    assert 'start' in emitted
    assert 'spawn' in emitted
    assert 'stop' in emitted
    assert 'exit' in emitted
Beispiel #6
0
def test_basic():
    emitted = []
    m = Manager()
    m.start()

    def cb(ev, msg):
        emitted.append((ev, msg['name']))

    # subscribe to all events
    chan = m.subscribe("EVENTS")
    chan.bind('.', cb)

    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=4)
    m.load(config)
    m.scale("dummy", 1)
    m.unload("dummy")

    time.sleep(0.2)
    m.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
Beispiel #7
0
def test_group():
    m = Manager()
    started = []
    stopped = []
    def cb(evtype, info):
        if evtype == "start":
            started.append(info['name'])
        elif evtype == "stop":
            stopped.append(info['name'])

    m.start()
    m.subscribe('start', cb)
    m.subscribe('stop', cb)
    testfile, cmd, args, wdir = dummy_cmd()
    m.add_process("ga:a", cmd, args=args, cwd=wdir, start=False)
    m.add_process("ga:b", cmd, args=args, cwd=wdir, start=False)
    m.add_process("gb:a", cmd, args=args, cwd=wdir, start=False)
    groups = sorted(m.get_groups())
    ga1 = m.get_group('ga')
    gb1 = m.get_group('gb')
    m.start_group("ga")
    m.stop_group("ga")
    time.sleep(0.2)
    m.remove_process("ga:a")
    ga2 = m.get_group('ga')
    m.stop_group("gb")

    def stop(handle):
        m.unsubscribe("start", cb)
        m.unsubscribe("stop", cb)
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.6, 0.0)
    m.run()

    assert groups == ['ga', 'gb']
    assert ga1 == ['ga:a', 'ga:b']
    assert gb1 == ['gb:a']
    assert started == ['ga:a', 'ga:b']
    assert stopped == ['ga:a', 'ga:b', 'gb:a']
    assert ga2 == ['ga:b']
Beispiel #8
0
def test_priority():
    m = Manager()
    started = []
    def cb(evtype, info):
        started.append(info['name'])

    m.start()
    m.subscribe('start', cb)

    testfile, cmd, args, wdir = dummy_cmd()
    m.add_process("a", cmd, args=args, cwd=wdir, start=False)
    m.add_process("d", cmd, args=args, cwd=wdir, start=False)
    m.add_process("b", cmd, args=args, cwd=wdir, start=False)
    m.start_processes()
    def stop(handle):
        m.unsubscribe("start", cb)
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.4, 0.0)
    m.run()

    assert started == ["a", "d", "b"]