本文整理汇总了Python中circus.client.CircusClient.stop方法的典型用法代码示例。如果您正苦于以下问题:Python CircusClient.stop方法的具体用法?Python CircusClient.stop怎么用?Python CircusClient.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类circus.client.CircusClient
的用法示例。
在下文中一共展示了CircusClient.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_dealer
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
def handle_dealer(self, command, opts, msg, endpoint, timeout, ssh_server,
ssh_keyfile):
if endpoint is not None:
client = CircusClient(endpoint=endpoint, timeout=timeout,
ssh_server=ssh_server,
ssh_keyfile=ssh_keyfile)
else:
client = self.client
try:
if isinstance(msg, list):
for i, c in enumerate(msg):
clm = self._console(client, c['cmd'], opts,
c['msg'])
print("%s: %s" % (i, clm))
else:
print(self._console(client, command, opts, msg))
except CallError as e:
msg = str(e)
if 'timed out' in str(e).lower():
msg += TIMEOUT_MSG
sys.stderr.write(msg)
return 1
finally:
if endpoint is not None:
client.stop()
return 0
示例2: TestCircus
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestCircus(unittest.TestCase):
def setUp(self):
self.arbiters = []
self.files = []
self.tmpfiles = []
self.cli = CircusClient()
def tearDown(self):
self._stop_runners()
for file in self.files + self.tmpfiles:
if os.path.exists(file):
os.remove(file)
self.cli.stop()
def get_tmpfile(self, content=None):
fd, file = mkstemp()
os.close(fd)
self.tmpfiles.append(file)
if content is not None:
with open(file, 'w') as f:
f.write(content)
return file
@classmethod
def _create_circus(cls, callable, plugins=None, stats=False, **kw):
resolve_name(callable) # used to check the callable
fd, testfile = mkstemp()
os.close(fd)
wdir = os.path.dirname(__file__)
args = ['generic.py', callable, testfile]
worker = {'cmd': _CMD, 'args': args, 'working_dir': wdir,
'name': 'test', 'graceful_timeout': 4}
worker.update(kw)
if stats:
arbiter = get_arbiter([worker], background=True, plugins=plugins,
stats_endpoint=DEFAULT_ENDPOINT_STATS,
debug=kw.get('debug', False))
else:
arbiter = get_arbiter([worker], background=True, plugins=plugins,
debug=kw.get('debug', False))
arbiter.start()
return testfile, arbiter
def _run_circus(self, callable, plugins=None, stats=False, **kw):
testfile, arbiter = TestCircus._create_circus(callable, plugins, stats,
**kw)
self.arbiters.append(arbiter)
self.files.append(testfile)
return testfile
def _stop_runners(self):
for arbiter in self.arbiters:
arbiter.stop()
self.arbiters = []
def call(self, cmd, **props):
msg = make_message(cmd, **props)
return self.cli.call(msg)
示例3: handle_dealer
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
def handle_dealer(self, cmd, opts, msg, endpoint, timeout, ssh_server,
ssh_keyfile):
if endpoint is not None:
client = CircusClient(endpoint=endpoint, timeout=timeout,
ssh_server=ssh_server,
ssh_keyfile=ssh_keyfile)
else:
client = self.client
try:
if isinstance(msg, list):
for i, command in enumerate(msg):
clm = self._console(client, command['cmd'], opts,
command['msg'])
print("%s: %s" % (i, clm))
else:
print(self._console(client, cmd, opts, msg))
except CallError as e:
sys.stderr.write(str(e) + " Try to raise the --timeout value\n")
return 1
finally:
if endpoint is not None:
client.stop()
return 0
示例4: TestWatcher
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestWatcher(TestCircus):
def setUp(self):
super(TestWatcher, self).setUp()
self.stream = QueueStream()
dummy_process = 'circus.tests.test_watcher.run_process'
self.test_file = self._run_circus(dummy_process,
stdout_stream={'stream': self.stream})
self.cli = CircusClient()
def call(self, cmd, **props):
msg = make_message(cmd, **props)
return self.cli.call(msg)
def tearDown(self):
super(TestWatcher, self).tearDown()
self.cli.stop()
def status(self, cmd, **props):
resp = self.call(cmd, **props)
return resp.get('status')
def numprocesses(self, cmd, **props):
resp = self.call(cmd, **props)
return resp.get('numprocesses')
def test_signal(self):
self.assertEquals(self.numprocesses('incr', name='test'), 2)
def get_pids():
return self.call('list', name='test').get('pids')
pids = get_pids()
self.assertEquals(len(pids), 2)
to_kill = pids[0]
self.assertEquals(self.status('signal', name='test', pid=to_kill,
signum=signal.SIGKILL), 'ok')
time.sleep(1) # wait for the process to die
# we still should have two processes, but not the same pids for them
pids = get_pids()
self.assertEquals(len(pids), 2)
self.assertTrue(to_kill not in pids)
def test_stats(self):
resp = self.call("stats").get('infos')
self.assertTrue("test" in resp)
watchers = resp['test']
self.assertEqual(watchers[watchers.keys()[0]]['cmdline'],
sys.executable.split(os.sep)[-1])
def test_streams(self):
time.sleep(1.)
# let's see what we got
self.assertTrue(self.stream.qsize() > 1)
示例5: TestWatcher
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestWatcher(TestCircus):
def setUp(self):
super(TestWatcher, self).setUp()
self.stream = QueueStream()
dummy_process = 'circus.tests.test_watcher.run_process'
self.test_file = self._run_circus(dummy_process,
stdout_stream={'stream': self.stream})
self.cli = CircusClient()
def call(self, cmd, **props):
msg = make_message(cmd, **props)
return self.cli.call(msg)
def tearDown(self):
super(TestWatcher, self).tearDown()
self.cli.stop()
def status(self, cmd, **props):
resp = self.call(cmd, **props)
return resp.get('status')
def numprocesses(self, cmd, **props):
resp = self.call(cmd, **props)
return resp.get('numprocesses')
def testSignal(self):
self.assertEquals(self.numprocesses("incr", name="test"), 2)
self.assertEquals(self.call("list", name="test").get('processes'),
[1, 2])
self.assertEquals(self.status("signal", name="test", process=2,
signum=signal.SIGKILL), "ok")
time.sleep(1.0)
self.assertEquals(self.call("list", name="test").get('processes'),
[1, 3])
processes = self.call("list", name="test").get('processes')
self.assertEquals(self.status("signal", name="test",
signum=signal.SIGKILL), "ok")
time.sleep(1.0)
self.assertNotEqual(self.call("list", name="test").get('processes'),
processes)
def testStats(self):
resp = self.call("stats").get('infos')
self.assertTrue("test" in resp)
self.assertEqual(resp['test']['1']['cmdline'],
sys.executable.split(os.sep)[-1])
def test_streams(self):
time.sleep(2.)
# let's see what we got
self.assertTrue(self.stream.qsize() > 1)
示例6: _client_test
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
def _client_test(self, ssh_server):
test_file = self._run_circus('circus.tests.support.run_process')
self.assertTrue(poll_for(test_file, 'START')) # process started
# playing around with the watcher
client = CircusClient(ssh_server=ssh_server)
def call(cmd, **props):
msg = make_message(cmd, **props)
return client.call(msg)
def status(cmd, **props):
resp = call(cmd, **props)
return resp.get('status')
def numprocesses(cmd, **props):
resp = call(cmd, **props)
return resp.get('numprocesses')
def numwatchers(cmd, **props):
resp = call(cmd, **props)
return resp.get('numwatchers')
def set(name, **opts):
return status("set", name=name, options=opts)
self.assertEquals(set("test", numprocesses=10), 'ok')
self.assertEquals(numprocesses("numprocesses"), 10)
self.assertEquals(set("test", numprocesses=1), 'ok')
self.assertEquals(numprocesses("numprocesses"), 1)
self.assertEquals(numwatchers("numwatchers"), 1)
self.assertEquals(call("list").get('watchers'), ['test'])
self.assertEquals(numprocesses("incr", name="test"), 2)
self.assertEquals(numprocesses("numprocesses"), 2)
self.assertEquals(numprocesses("incr", name="test", nb=2), 4)
self.assertEquals(numprocesses("decr", name="test", nb=3), 1)
self.assertEquals(numprocesses("numprocesses"), 1)
self.assertEquals(set("test", env={"test": 1, "test": 2}), 'error')
self.assertEquals(set("test", env={"test": '1', "test": '2'}),
'ok')
resp = call('get', name='test', keys=['env'])
options = resp.get('options', {})
self.assertEquals(options.get('env'), {'test': '1', 'test': '2'})
resp = call('stats', name='test')
self.assertEqual(resp['status'], 'ok')
resp = call('globaloptions', name='test')
self.assertEqual(resp['options']['pubsub_endpoint'],
'tcp://127.0.0.1:5556')
client.stop()
示例7: test_handler
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
def test_handler(self):
self._run_circus('circus.tests.test_client.run_process')
time.sleep(.5)
# playing around with the watcher
client = CircusClient()
def call(cmd, **props):
msg = make_message(cmd, **props)
return client.call(msg)
def status(cmd, **props):
resp = call(cmd, **props)
return resp.get('status')
def numprocesses(cmd, **props):
resp = call(cmd, **props)
return resp.get('numprocesses')
def numwatchers(cmd, **props):
resp = call(cmd, **props)
return resp.get('numwatchers')
def set(name, **opts):
return status("set", name=name, options=opts)
self.assertEquals(set("test", numprocesses=10), 'ok')
self.assertEquals(numprocesses("numprocesses"), 10)
self.assertEquals(set("test", numprocesses=1), 'ok')
self.assertEquals(numprocesses("numprocesses"), 1)
self.assertEquals(numwatchers("numwatchers"), 1)
self.assertEquals(call("list").get('watchers'), ['test'])
self.assertEquals(call("list", name="test").get('processes'), [10])
self.assertEquals(numprocesses("incr", name="test"), 2)
self.assertEquals(numprocesses("numprocesses"), 2)
self.assertEquals(numprocesses("decr", name="test"), 1)
self.assertEquals(numprocesses("numprocesses"), 1)
self.assertEquals(set("test", env={"test": 1, "test": 2}), 'error')
self.assertEquals(set("test", env={"test": '1', "test": '2'}),
'ok')
resp = call('get', name='test', keys=['env'])
options = resp.get('options', {})
self.assertEquals(options.get('env'), {'test': '1', 'test': '2'})
resp = call('stats', name='test')
self.assertEqual(resp['status'], 'ok')
resp = call('globaloptions', name='test')
self.assertEqual(resp['options']['pubsub_endpoint'],
'tcp://127.0.0.1:5556')
client.stop()
示例8: TestWatcher
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestWatcher(TestCircus):
def setUp(self):
super(TestWatcher, self).setUp()
dummy_process = 'circus.tests.test_watcher.run_process'
self.test_file = self._run_circus(dummy_process)
self.cli = CircusClient()
def call(self, cmd, **props):
msg = make_message(cmd, **props)
return self.cli.call(msg)
def tearDown(self):
super(TestWatcher, self).tearDown()
self.cli.stop()
def status(self, cmd, **props):
resp = self.call(cmd, **props)
return resp.get('status')
def numprocesses(self, cmd, **props):
resp = self.call(cmd, **props)
return resp.get('numprocesses')
def testSignal(self):
self.assertEquals(self.numprocesses("incr", name="test"), 2)
self.assertEquals(self.call("list", name="test").get('processes'),
[1, 2])
self.assertEquals(self.status("signal", name="test", process=2,
signum=signal.SIGKILL), "ok")
time.sleep(1.0)
self.assertEquals(self.call("list", name="test").get('processes'),
[1, 3])
processes = self.call("list", name="test").get('processes')
self.assertEquals(self.status("signal", name="test",
signum=signal.SIGKILL), "ok")
time.sleep(1.0)
self.assertNotEqual(self.call("list", name="test").get('processes'),
processes)
def testStats(self):
resp = self.call("stats").get('infos')
self.assertTrue("test" in resp)
self.assertEqual(resp['test']['1']['cmdline'], 'python')
示例9: handle_dealer
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
def handle_dealer(self, cmd, opts, msg, endpoint, timeout):
client = CircusClient(endpoint=endpoint, timeout=timeout)
try:
if isinstance(msg, list):
for i, cmd in enumerate(msg):
clm = self._console(client, cmd, opts, msg)
print("%s: %s" % (i, clm))
else:
print(self._console(client, cmd, opts, msg))
except CallError as e:
sys.stderr.write(str(e))
return 1
finally:
client.stop()
return 0
示例10: TestWatcher
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestWatcher(TestCircus):
def setUp(self):
super(TestWatcher, self).setUp()
dummy_process = 'circus.tests.test_stream.run_process'
fd, log = tempfile.mkstemp()
self.log = log
os.close(fd)
stream = {'stream': FileStream(log)}
self.test_file = self._run_circus(dummy_process,
stdout_stream=stream, stderr_stream=stream, debug=True)
self.cli = CircusClient()
def call(self, cmd, **props):
msg = make_message(cmd, **props)
return self.cli.call(msg)
def tearDown(self):
super(TestWatcher, self).tearDown()
self.cli.stop()
os.remove(self.log)
def test_stream(self):
time.sleep(2.)
self.call("stats").get('infos')
# let's see what we got in the file
with open(self.log) as f:
data = f.read()
self.assertTrue('stderr' in data)
self.assertTrue('stdout' in data)
# restarting
self.call('restart')
time.sleep(1.)
current = time.time()
# should be running
with open(self.log) as f:
data = f.readlines()
# last log should be less than one second old
last = data[-1]
delta = abs(current - int(last.split('-')[0]))
self.assertTrue(delta < 1, delta)
示例11: TestWatcher
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestWatcher(TestCircus):
def setUp(self):
super(TestWatcher, self).setUp()
dummy_process = "circus.tests.test_stream.run_process"
fd, self.stdout = tempfile.mkstemp()
os.close(fd)
fd, self.stderr = tempfile.mkstemp()
os.close(fd)
self.test_file = self._run_circus(
dummy_process,
stdout_stream={"stream": FileStream(self.stdout)},
stderr_stream={"stream": FileStream(self.stderr)},
debug=True,
)
self.cli = CircusClient()
def call(self, cmd, **props):
msg = make_message(cmd, **props)
return self.cli.call(msg)
def tearDown(self):
super(TestWatcher, self).tearDown()
self.cli.stop()
os.remove(self.stdout)
os.remove(self.stderr)
def test_stream(self):
# wait for the process to be started
self.assertTrue(poll_for(self.stdout, "stdout"))
self.assertTrue(poll_for(self.stderr, "stderr"))
# clean slate
truncate_file(self.stdout)
truncate_file(self.stderr)
# restart and make sure streams are still working
self.call("restart")
# wait for the process to be restarted
self.assertTrue(poll_for(self.stdout, "stdout"))
self.assertTrue(poll_for(self.stderr, "stderr"))
示例12: LiveClient
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class LiveClient(object):
def __init__(self, endpoint):
self.endpoint = str(endpoint)
self.client = CircusClient(endpoint=self.endpoint)
self.connected = False
self.watchers = []
self.stats = defaultdict(list)
self.refresher = Refresher(self)
self.dstats = []
def stop(self):
self.client.stop()
self.refresher.running = False
self.refresher.join()
def verify(self):
self.watchers = []
# trying to list the watchers
msg = cmds['list'].make_message()
try:
res = self.client.call(msg)
self.connected = True
for watcher in res['watchers']:
msg = cmds['options'].make_message(name=watcher)
options = self.client.call(msg)
self.watchers.append((watcher, options['options']))
self.watchers.sort()
if not self.refresher.running:
self.refresher.start()
except CallError:
self.connected = False
def killproc(self, name, pid):
msg = cmds['signal'].make_message(name=name, process=int(pid),
signum=9)
res = self.client.call(msg)
self.verify() # will do better later
return res['status'] == 'ok'
def get_option(self, name, option):
watchers = dict(self.watchers)
return watchers[name][option]
def get_global_options(self):
msg = cmds['globaloptions'].make_message()
options = self.client.call(msg)
return options['options']
def get_options(self, name):
watchers = dict(self.watchers)
return watchers[name].items()
def incrproc(self, name):
msg = cmds['incr'].make_message(name=name)
res = self.client.call(msg)
self.verify() # will do better later
return res['numprocesses']
def decrproc(self, name):
msg = cmds['decr'].make_message(name=name)
res = self.client.call(msg)
self.verify() # will do better later
return res['numprocesses']
def get_stats(self, name, start=0, end=-1):
return self.stats[name][start:end]
def get_dstats(self, field, start=0, end=-1):
stats = self.dstats[start:end]
res = []
for stat in stats:
res.append(stat[field])
return res
def get_pids(self, name):
msg = cmds['list'].make_message(name=name)
res = self.client.call(msg)
return res['processes']
def get_series(self, name, pid, field, start=0, end=-1):
stats = self.get_stats(name, start, end)
res = []
pid = str(pid)
for stat in stats:
if pid not in stat:
continue
res.append(stat[pid][field])
return res
def get_status(self, name):
msg = cmds['status'].make_message(name=name)
res = self.client.call(msg)
return res['status']
def switch_status(self, name):
msg = cmds['status'].make_message(name=name)
res = self.client.call(msg)
status = res['status']
if status == 'active':
# stopping the watcher
#.........这里部分代码省略.........
示例13: TestTrainer
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestTrainer(TestCircus):
def setUp(self):
super(TestTrainer, self).setUp()
dummy_process = 'circus.tests.test_arbiter.run_dummy'
self.test_file = self._run_circus(dummy_process)
self.cli = CircusClient()
def tearDown(self):
super(TestTrainer, self).tearDown()
self.cli.stop()
def test_numwatchers(self):
msg = make_message("numwatchers")
resp = self.cli.call(msg)
self.assertEqual(resp.get("numwatchers"), 1)
def test_numprocesses(self):
msg = make_message("numprocesses")
resp = self.cli.call(msg)
self.assertEqual(resp.get("numprocesses"), 1)
def test_processes(self):
msg1 = make_message("list", name="test")
resp = self.cli.call(msg1)
self.assertEqual(resp.get('processes'), [1])
msg2 = make_message("incr", name="test")
self.cli.call(msg2)
resp = self.cli.call(msg1)
self.assertEqual(resp.get('processes'), [1, 2])
def test_watchers(self):
resp = self.cli.call(make_message("list"))
self.assertEqual(resp.get('watchers'), ["test"])
def _get_cmd(self):
fd, testfile = mkstemp()
os.close(fd)
cmd = '%s generic.py %s %s' % (sys.executable,
'circus.tests.test_arbiter.run_dummy', testfile)
return cmd
def _get_cmd_args(self):
cmd = sys.executable
args = ['generic.py', 'circus.tests.test_arbiter.run_dummy1']
return cmd, args
def test_add_watcher(self):
msg = make_message("add", name="test1", cmd=self._get_cmd())
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
def test_add_watcher1(self):
msg = make_message("add", name="test1", cmd=self._get_cmd())
self.cli.call(msg)
resp = self.cli.call(make_message("list"))
self.assertEqual(resp.get('watchers'), ["test", "test1"])
def test_add_watcher2(self):
msg = make_message("add", name="test1", cmd=self._get_cmd())
self.cli.call(msg)
resp = self.cli.call(make_message("numwatchers"))
self.assertEqual(resp.get("numwatchers"), 2)
def test_add_watcher3(self):
msg = make_message("add", name="test1", cmd=self._get_cmd())
self.cli.call(msg)
resp = self.cli.call(msg)
self.assertTrue(resp.get('status'), 'error')
def test_add_watcher4(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args)
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
def test_add_watcher5(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args)
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
resp = self.cli.call(make_message("start", name="test1"))
self.assertEqual(resp.get("status"), "ok")
resp = self.cli.call(make_message("status", name="test1"))
self.assertEqual(resp.get("status"), "active")
def test_add_watcher6(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args,
start=True)
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
resp = self.cli.call(make_message("status", name="test1"))
self.assertEqual(resp.get("status"), "active")
#.........这里部分代码省略.........
示例14: TestTrainer
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestTrainer(TestCircus):
def setUp(self):
super(TestTrainer, self).setUp()
dummy_process = "circus.tests.test_arbiter.run_dummy"
self.test_file = self._run_circus(dummy_process)
self.cli = CircusClient()
def tearDown(self):
super(TestTrainer, self).tearDown()
self.cli.stop()
def test_numwatchers(self):
msg = make_message("numwatchers")
resp = self.cli.call(msg)
self.assertEqual(resp.get("numwatchers"), 1)
def test_numprocesses(self):
msg = make_message("numprocesses")
resp = self.cli.call(msg)
self.assertEqual(resp.get("numprocesses"), 1)
def test_processes(self):
msg1 = make_message("list", name="test")
resp = self.cli.call(msg1)
self.assertEqual(resp.get("processes"), [1])
msg2 = make_message("incr", name="test")
self.cli.call(msg2)
resp = self.cli.call(msg1)
self.assertEqual(resp.get("processes"), [1, 2])
def test_watchers(self):
resp = self.cli.call(make_message("list"))
self.assertEqual(resp.get("watchers"), ["test"])
def _get_cmd(self):
fd, testfile = mkstemp()
os.close(fd)
cmd = "%s generic.py %s %s" % (sys.executable, "circus.tests.test_arbiter.run_dummy", testfile)
return cmd
def _get_cmd_args(self):
cmd = sys.executable
args = ["generic.py", "circus.tests.test_arbiter.run_dummy1"]
return cmd, args
def test_add_watcher(self):
msg = make_message("add", name="test1", cmd=self._get_cmd())
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
def test_add_watcher1(self):
msg = make_message("add", name="test1", cmd=self._get_cmd())
self.cli.call(msg)
resp = self.cli.call(make_message("list"))
self.assertEqual(resp.get("watchers"), ["test", "test1"])
def test_add_watcher2(self):
msg = make_message("add", name="test1", cmd=self._get_cmd())
self.cli.call(msg)
resp = self.cli.call(make_message("numwatchers"))
self.assertEqual(resp.get("numwatchers"), 2)
def test_add_watcher3(self):
msg = make_message("add", name="test1", cmd=self._get_cmd())
self.cli.call(msg)
resp = self.cli.call(msg)
self.assertTrue(resp.get("status"), "error")
def test_add_watcher4(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args)
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
def test_add_watcher5(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args)
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
resp = self.cli.call(make_message("start", name="test1"))
self.assertEqual(resp.get("status"), "ok")
resp = self.cli.call(make_message("status", name="test1"))
self.assertEqual(resp.get("status"), "active")
def test_add_watcher6(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args, start=True)
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
resp = self.cli.call(make_message("status", name="test1"))
self.assertEqual(resp.get("status"), "active")
def test_add_watcher7(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args, start=True, options={"flapping_window": 100})
#.........这里部分代码省略.........
示例15: TestTrainer
# 需要导入模块: from circus.client import CircusClient [as 别名]
# 或者: from circus.client.CircusClient import stop [as 别名]
class TestTrainer(TestCircus):
def setUp(self):
super(TestTrainer, self).setUp()
dummy_process = 'circus.tests.support.run_process'
self.test_file = self._run_circus(dummy_process)
self.cli = CircusClient()
def tearDown(self):
super(TestTrainer, self).tearDown()
self.cli.stop()
def test_numwatchers(self):
msg = make_message("numwatchers")
resp = self.cli.call(msg)
self.assertEqual(resp.get("numwatchers"), 1)
def test_numprocesses(self):
msg = make_message("numprocesses")
resp = self.cli.call(msg)
self.assertEqual(resp.get("numprocesses"), 1)
def test_processes(self):
msg1 = make_message("list", name="test")
resp = self.cli.call(msg1)
self.assertEqual(len(resp.get('pids')), 1)
msg2 = make_message("incr", name="test")
self.cli.call(msg2)
resp = self.cli.call(msg1)
self.assertEqual(len(resp.get('pids')), 2)
self.cli.send_message("incr", name="test", nb=2)
resp = self.cli.call(msg1)
self.assertEqual(len(resp.get('pids')), 4)
def test_watchers(self):
resp = self.cli.call(make_message("list"))
self.assertEqual(resp.get('watchers'), ["test"])
def _get_cmd(self):
fd, testfile = mkstemp()
os.close(fd)
cmd = '%s generic.py %s %s' % (
sys.executable,
'circus.tests.support.run_process',
testfile)
return cmd
def _get_cmd_args(self):
cmd = sys.executable
args = ['generic.py', 'circus.tests.support.run_process']
return cmd, args
def _get_options(self, **kwargs):
if 'graceful_timeout' not in kwargs:
kwargs['graceful_timeout'] = 4
return kwargs
def test_add_watcher(self):
msg = make_message("add", name="test1", cmd=self._get_cmd(),
options=self._get_options())
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
def test_add_watcher1(self):
msg = make_message("add", name="test1", cmd=self._get_cmd(),
options=self._get_options())
self.cli.call(msg)
resp = self.cli.call(make_message("list"))
self.assertEqual(resp.get('watchers'), ["test", "test1"])
def test_add_watcher2(self):
msg = make_message("add", name="test1", cmd=self._get_cmd(),
options=self._get_options())
self.cli.call(msg)
resp = self.cli.call(make_message("numwatchers"))
self.assertEqual(resp.get("numwatchers"), 2)
def test_add_watcher3(self):
msg = make_message("add", name="test1", cmd=self._get_cmd(),
options=self._get_options())
self.cli.call(msg)
resp = self.cli.call(msg)
self.assertTrue(resp.get('status'), 'error')
def test_add_watcher4(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args,
options=self._get_options())
resp = self.cli.call(msg)
self.assertEqual(resp.get("status"), "ok")
def test_add_watcher5(self):
cmd, args = self._get_cmd_args()
msg = make_message("add", name="test1", cmd=cmd, args=args,
options=self._get_options())
resp = self.cli.call(msg)
#.........这里部分代码省略.........