##// END OF EJS Templates
don't color engine tracebacks in tests
MinRK -
Show More
@@ -1,122 +1,126 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
17 from subprocess import Popen
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 from IPython.parallel.apps.launcher import (LocalProcessLauncher,
21 from IPython.parallel.apps.launcher import (LocalProcessLauncher,
22 ipengine_cmd_argv,
22 ipengine_cmd_argv,
23 ipcontroller_cmd_argv,
23 ipcontroller_cmd_argv,
24 SIGKILL,
24 SIGKILL,
25 ProcessStateError,
25 ProcessStateError,
26 )
26 )
27
27
28 # globals
28 # globals
29 launchers = []
29 launchers = []
30 blackhole = open(os.devnull, 'w')
30 blackhole = open(os.devnull, 'w')
31
31
32 # Launcher class
32 # Launcher class
33 class TestProcessLauncher(LocalProcessLauncher):
33 class TestProcessLauncher(LocalProcessLauncher):
34 """subclass LocalProcessLauncher, to prevent extra sockets and threads being created on Windows"""
34 """subclass LocalProcessLauncher, to prevent extra sockets and threads being created on Windows"""
35 def start(self):
35 def start(self):
36 if self.state == 'before':
36 if self.state == 'before':
37 self.process = Popen(self.args,
37 self.process = Popen(self.args,
38 stdout=blackhole, stderr=blackhole,
38 stdout=blackhole, stderr=blackhole,
39 env=os.environ,
39 env=os.environ,
40 cwd=self.work_dir
40 cwd=self.work_dir
41 )
41 )
42 self.notify_start(self.process.pid)
42 self.notify_start(self.process.pid)
43 self.poll = self.process.poll
43 self.poll = self.process.poll
44 else:
44 else:
45 s = 'The process was already started and has state: %r' % self.state
45 s = 'The process was already started and has state: %r' % self.state
46 raise ProcessStateError(s)
46 raise ProcessStateError(s)
47
47
48 # nose setup/teardown
48 # nose setup/teardown
49
49
50 def setup():
50 def setup():
51 cluster_dir = os.path.join(get_ipython_dir(), 'profile_iptest')
51 cluster_dir = os.path.join(get_ipython_dir(), 'profile_iptest')
52 engine_json = os.path.join(cluster_dir, 'security', 'ipcontroller-engine.json')
52 engine_json = os.path.join(cluster_dir, 'security', 'ipcontroller-engine.json')
53 client_json = os.path.join(cluster_dir, 'security', 'ipcontroller-client.json')
53 client_json = os.path.join(cluster_dir, 'security', 'ipcontroller-client.json')
54 for json in (engine_json, client_json):
54 for json in (engine_json, client_json):
55 if os.path.exists(json):
55 if os.path.exists(json):
56 os.remove(json)
56 os.remove(json)
57
57
58 cp = TestProcessLauncher()
58 cp = TestProcessLauncher()
59 cp.cmd_and_args = ipcontroller_cmd_argv + \
59 cp.cmd_and_args = ipcontroller_cmd_argv + \
60 ['--profile=iptest', '--log-level=50', '--ping=250', '--dictdb']
60 ['--profile=iptest', '--log-level=50', '--ping=250', '--dictdb']
61 cp.start()
61 cp.start()
62 launchers.append(cp)
62 launchers.append(cp)
63 tic = time.time()
63 tic = time.time()
64 while not os.path.exists(engine_json) or not os.path.exists(client_json):
64 while not os.path.exists(engine_json) or not os.path.exists(client_json):
65 if cp.poll() is not None:
65 if cp.poll() is not None:
66 print cp.poll()
66 print cp.poll()
67 raise RuntimeError("The test controller failed to start.")
67 raise RuntimeError("The test controller failed to start.")
68 elif time.time()-tic > 15:
68 elif time.time()-tic > 15:
69 raise RuntimeError("Timeout waiting for the test controller to start.")
69 raise RuntimeError("Timeout waiting for the test controller to start.")
70 time.sleep(0.1)
70 time.sleep(0.1)
71 add_engines(1)
71 add_engines(1)
72
72
73 def add_engines(n=1, profile='iptest', total=False):
73 def add_engines(n=1, profile='iptest', total=False):
74 """add a number of engines to a given profile.
74 """add a number of engines to a given profile.
75
75
76 If total is True, then already running engines are counted, and only
76 If total is True, then already running engines are counted, and only
77 the additional engines necessary (if any) are started.
77 the additional engines necessary (if any) are started.
78 """
78 """
79 rc = Client(profile=profile)
79 rc = Client(profile=profile)
80 base = len(rc)
80 base = len(rc)
81
81
82 if total:
82 if total:
83 n = max(n - base, 0)
83 n = max(n - base, 0)
84
84
85 eps = []
85 eps = []
86 for i in range(n):
86 for i in range(n):
87 ep = TestProcessLauncher()
87 ep = TestProcessLauncher()
88 ep.cmd_and_args = ipengine_cmd_argv + ['--profile=%s'%profile, '--log-level=50']
88 ep.cmd_and_args = ipengine_cmd_argv + [
89 '--profile=%s' % profile,
90 '--log-level=50',
91 '--InteractiveShell.colors=nocolor'
92 ]
89 ep.start()
93 ep.start()
90 launchers.append(ep)
94 launchers.append(ep)
91 eps.append(ep)
95 eps.append(ep)
92 tic = time.time()
96 tic = time.time()
93 while len(rc) < base+n:
97 while len(rc) < base+n:
94 if any([ ep.poll() is not None for ep in eps ]):
98 if any([ ep.poll() is not None for ep in eps ]):
95 raise RuntimeError("A test engine failed to start.")
99 raise RuntimeError("A test engine failed to start.")
96 elif time.time()-tic > 15:
100 elif time.time()-tic > 15:
97 raise RuntimeError("Timeout waiting for engines to connect.")
101 raise RuntimeError("Timeout waiting for engines to connect.")
98 time.sleep(.1)
102 time.sleep(.1)
99 rc.spin()
103 rc.spin()
100 rc.close()
104 rc.close()
101 return eps
105 return eps
102
106
103 def teardown():
107 def teardown():
104 time.sleep(1)
108 time.sleep(1)
105 while launchers:
109 while launchers:
106 p = launchers.pop()
110 p = launchers.pop()
107 if p.poll() is None:
111 if p.poll() is None:
108 try:
112 try:
109 p.stop()
113 p.stop()
110 except Exception as e:
114 except Exception as e:
111 print e
115 print e
112 pass
116 pass
113 if p.poll() is None:
117 if p.poll() is None:
114 time.sleep(.25)
118 time.sleep(.25)
115 if p.poll() is None:
119 if p.poll() is None:
116 try:
120 try:
117 print 'cleaning up test process...'
121 print 'cleaning up test process...'
118 p.signal(SIGKILL)
122 p.signal(SIGKILL)
119 except:
123 except:
120 print "couldn't shutdown process: ", p
124 print "couldn't shutdown process: ", p
121 blackhole.close()
125 blackhole.close()
122
126
General Comments 0
You need to be logged in to leave comments. Login now