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