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