##// END OF EJS Templates
better handle controller/engines never starting in tests
MinRK -
Show More
@@ -1,74 +1,80 b''
1 1 """toplevel setup/teardown for parallel tests."""
2 2
3 3 #-------------------------------------------------------------------------------
4 4 # Copyright (C) 2011 The IPython Development Team
5 5 #
6 6 # Distributed under the terms of the BSD License. The full license is in
7 7 # the file COPYING, distributed as part of this software.
8 8 #-------------------------------------------------------------------------------
9 9
10 10 #-------------------------------------------------------------------------------
11 11 # Imports
12 12 #-------------------------------------------------------------------------------
13 13
14 14 import os
15 15 import tempfile
16 16 import time
17 17 from subprocess import Popen, PIPE, STDOUT
18 18
19 19 from IPython.utils.path import get_ipython_dir
20 20 from IPython.parallel import Client
21 21
22 22 processes = []
23 23 blackhole = tempfile.TemporaryFile()
24 24
25 25 # nose setup/teardown
26 26
27 27 def setup():
28 cp = Popen('ipcontroller --profile iptest -r --log-level 10 --log-to-file'.split(), stdout=blackhole, stderr=STDOUT)
28 cp = Popen('ipcontroller --profile iptest -r --log-level 10 --log-to-file --usethreads'.split(), stdout=blackhole, stderr=STDOUT)
29 processes.append(cp)
29 30 engine_json = os.path.join(get_ipython_dir(), 'cluster_iptest', 'security', 'ipcontroller-engine.json')
30 31 client_json = os.path.join(get_ipython_dir(), 'cluster_iptest', 'security', 'ipcontroller-client.json')
31 while not os.path.exists(engine_json) and not os.path.exists(client_json):
32 tic = time.time()
33 while not os.path.exists(engine_json) or not os.path.exists(client_json):
34 if cp.poll() is not None:
35 print cp.poll()
36 raise RuntimeError("The test controller failed to start.")
37 elif time.time()-tic > 10:
38 raise RuntimeError("Timeout waiting for the test controller to start.")
32 39 time.sleep(0.1)
33 processes.append(cp)
34 40 add_engines(1)
35 c = Client(profile='iptest')
36 while not c.ids:
37 time.sleep(.1)
38 c.spin()
39 c.close()
40 41
41 42 def add_engines(n=1, profile='iptest'):
42 43 rc = Client(profile=profile)
43 44 base = len(rc)
44 45 eps = []
45 46 for i in range(n):
46 47 ep = Popen(['ipengine']+ ['--profile', profile, '--log-level', '10', '--log-to-file'], stdout=blackhole, stderr=STDOUT)
47 48 # ep.start()
48 49 processes.append(ep)
49 50 eps.append(ep)
51 tic = time.time()
50 52 while len(rc) < base+n:
53 if any([ ep.poll() is not None for ep in eps ]):
54 raise RuntimeError("A test engine failed to start.")
55 elif time.time()-tic > 10:
56 raise RuntimeError("Timeout waiting for engines to connect.")
51 57 time.sleep(.1)
52 58 rc.spin()
53 59 rc.close()
54 60 return eps
55 61
56 62 def teardown():
57 63 time.sleep(1)
58 64 while processes:
59 65 p = processes.pop()
60 66 if p.poll() is None:
61 67 try:
62 68 p.terminate()
63 69 except Exception, e:
64 70 print e
65 71 pass
66 72 if p.poll() is None:
67 73 time.sleep(.25)
68 74 if p.poll() is None:
69 75 try:
70 76 print 'killing'
71 77 p.kill()
72 78 except:
73 79 print "couldn't shutdown process: ", p
74 80
General Comments 0
You need to be logged in to leave comments. Login now