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