__init__.py
80 lines
| 2.7 KiB
| text/x-python
|
PythonLexer
MinRK
|
r3637 | """toplevel setup/teardown for parallel tests.""" | ||
MinRK
|
r3664 | #------------------------------------------------------------------------------- | ||
# Copyright (C) 2011 The IPython Development Team | ||||
# | ||||
# Distributed under the terms of the BSD License. The full license is in | ||||
# the file COPYING, distributed as part of this software. | ||||
#------------------------------------------------------------------------------- | ||||
#------------------------------------------------------------------------------- | ||||
# Imports | ||||
#------------------------------------------------------------------------------- | ||||
MinRK
|
r3678 | import os | ||
MinRK
|
r3654 | import tempfile | ||
MinRK
|
r3595 | import time | ||
MinRK
|
r3654 | from subprocess import Popen, PIPE, STDOUT | ||
MinRK
|
r3595 | |||
MinRK
|
r3678 | from IPython.utils.path import get_ipython_dir | ||
MinRK
|
r3673 | from IPython.parallel import Client | ||
MinRK
|
r3595 | |||
MinRK
|
r3637 | processes = [] | ||
MinRK
|
r3654 | blackhole = tempfile.TemporaryFile() | ||
MinRK
|
r3637 | |||
# nose setup/teardown | ||||
MinRK
|
r3595 | |||
def setup(): | ||||
MinRK
|
r3680 | cp = Popen('ipcontroller --profile iptest -r --log-level 10 --log-to-file --usethreads'.split(), stdout=blackhole, stderr=STDOUT) | ||
processes.append(cp) | ||||
MinRK
|
r3678 | engine_json = os.path.join(get_ipython_dir(), 'cluster_iptest', 'security', 'ipcontroller-engine.json') | ||
client_json = os.path.join(get_ipython_dir(), 'cluster_iptest', 'security', 'ipcontroller-client.json') | ||||
MinRK
|
r3680 | tic = time.time() | ||
while not os.path.exists(engine_json) or not os.path.exists(client_json): | ||||
if cp.poll() is not None: | ||||
print cp.poll() | ||||
raise RuntimeError("The test controller failed to start.") | ||||
elif time.time()-tic > 10: | ||||
raise RuntimeError("Timeout waiting for the test controller to start.") | ||||
MinRK
|
r3678 | time.sleep(0.1) | ||
MinRK
|
r3664 | add_engines(1) | ||
MinRK
|
r3595 | |||
MinRK
|
r3664 | def add_engines(n=1, profile='iptest'): | ||
MinRK
|
r3673 | rc = Client(profile=profile) | ||
MinRK
|
r3664 | base = len(rc) | ||
eps = [] | ||||
for i in range(n): | ||||
MinRK
|
r3672 | ep = Popen(['ipengine']+ ['--profile', profile, '--log-level', '10', '--log-to-file'], stdout=blackhole, stderr=STDOUT) | ||
MinRK
|
r3664 | # ep.start() | ||
processes.append(ep) | ||||
eps.append(ep) | ||||
MinRK
|
r3680 | tic = time.time() | ||
MinRK
|
r3664 | while len(rc) < base+n: | ||
MinRK
|
r3680 | if any([ ep.poll() is not None for ep in eps ]): | ||
raise RuntimeError("A test engine failed to start.") | ||||
elif time.time()-tic > 10: | ||||
raise RuntimeError("Timeout waiting for engines to connect.") | ||||
MinRK
|
r3664 | time.sleep(.1) | ||
rc.spin() | ||||
rc.close() | ||||
return eps | ||||
MinRK
|
r3595 | |||
def teardown(): | ||||
time.sleep(1) | ||||
while processes: | ||||
p = processes.pop() | ||||
if p.poll() is None: | ||||
try: | ||||
p.terminate() | ||||
except Exception, e: | ||||
print e | ||||
pass | ||||
if p.poll() is None: | ||||
time.sleep(.25) | ||||
if p.poll() is None: | ||||
try: | ||||
print 'killing' | ||||
p.kill() | ||||
except: | ||||
MinRK
|
r3655 | print "couldn't shutdown process: ", p | ||
MinRK
|
r3595 | |||