def test_events(): emitted = [] m = Manager() m.start() def cb(ev, msg): emitted.append((ev, msg['name'])) # subscribe to all events m.on('.', cb) testfile, cmd, args, wdir = dummy_cmd() m.add_process("dummy", cmd, args=args, cwd=wdir, numprocesses=4) m.ttin("dummy", 1) m.remove_process("dummy") time.sleep(0.2) m.stop() m.run() assert ('create', 'dummy') in emitted assert ('start', 'dummy') in emitted assert ('update', 'dummy') in emitted assert ('stop', 'dummy') in emitted assert ('delete', 'dummy') in emitted
def test_manager_hooks(): hooks = create_hooks(['create', 'start', 'update', 'stop', 'delete', 'proc.dummy.start', 'proc.dummy.spawn', 'proc.dummy.stop', 'proc.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() m.add_process("dummy", cmd, args=args, cwd=wdir, numprocesses=4) m.ttin("dummy", 1) m.remove_process("dummy") time.sleep(0.2) def on_stop(manager): s.stop() m.stop(on_stop) m.run() assert ('create', 'dummy') in emitted assert ('start', 'dummy') in emitted assert ('update', 'dummy') in emitted assert ('stop', 'dummy') in emitted assert ('delete', 'dummy') in emitted assert ('proc.dummy.start', 'dummy') in emitted assert ('proc.dummy.spawn', 'dummy') in emitted assert ('proc.dummy.stop', 'dummy') in emitted assert ('proc.dummy.exit', 'dummy') in emitted
def test_ttin(): m = Manager() m.start() testfile, cmd, args, wdir = dummy_cmd() m.add_process("dummy", cmd, args=args, cwd=wdir, numprocesses=1) state = m.get_process_state("dummy") assert len(state.running) == 1 ret = m.ttin("dummy", 1) assert ret == 2 time.sleep(0.2) assert len(state.running) == 2 ret = m.ttin("dummy", 1) assert ret == 3 time.sleep(0.2) assert len(state.running) == 3 ret = m.ttin("dummy", 3) assert ret == 6 time.sleep(0.2) assert len(state.running) == 6 m.stop() m.run()
def test_manager_hooks(): hooks = create_hooks([ 'create', 'start', 'update', 'stop', 'delete', 'proc.dummy.start', 'proc.dummy.spawn', 'proc.dummy.stop', 'proc.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() m.add_process("dummy", cmd, args=args, cwd=wdir, numprocesses=4) m.ttin("dummy", 1) m.remove_process("dummy") time.sleep(0.2) def on_stop(manager): s.stop() m.stop(on_stop) m.run() assert ('create', 'dummy') in emitted assert ('start', 'dummy') in emitted assert ('update', 'dummy') in emitted assert ('stop', 'dummy') in emitted assert ('delete', 'dummy') in emitted assert ('proc.dummy.start', 'dummy') in emitted assert ('proc.dummy.spawn', 'dummy') in emitted assert ('proc.dummy.stop', 'dummy') in emitted assert ('proc.dummy.exit', 'dummy') in emitted