1
1
"""Test CLI application behavior"""
2
+ import glob
2
3
import json
3
4
import os
4
5
import sys
@@ -169,12 +170,27 @@ def test_ipcluster_list(Cluster):
169
170
170
171
@pytest .mark .parametrize ("daemonize" , (False , True ))
171
172
def test_ipcluster_start_stop (request , ipython_dir , daemonize ):
172
- default_profile = ProfileDir .find_profile_dir_by_name (ipython_dir ).location
173
+ default_profile = ProfileDir .find_profile_dir_by_name (ipython_dir )
174
+ default_profile_dir = default_profile .location
175
+
176
+ # cleanup the security directory to avoid leaking files from one test to the next
177
+ def cleanup_security ():
178
+ for f in glob .glob (os .path .join (default_profile .security_dir , "*.json" )):
179
+ print (f"Cleaning up { f } " )
180
+ try :
181
+ os .remove (f )
182
+ except Exception as e :
183
+ print (f"Error removing { f } : { e } " )
184
+
185
+ request .addfinalizer (cleanup_security )
186
+
173
187
n = 2
174
188
start_args = ["-n" , str (n )]
175
189
if daemonize :
176
190
start_args .append ("--daemonize" )
177
- start = Popen ([sys .executable , "-m" , "ipyparallel.cluster" , "start" ] + start_args )
191
+ start = Popen (
192
+ [sys .executable , "-m" , "ipyparallel.cluster" , "start" , "--debug" ] + start_args
193
+ )
178
194
request .addfinalizer (start .terminate )
179
195
if daemonize :
180
196
# if daemonize, should exit after starting
@@ -183,7 +199,7 @@ def test_ipcluster_start_stop(request, ipython_dir, daemonize):
183
199
# wait for file to appear
184
200
# only need this if not daemonize
185
201
cluster_file = ipp .Cluster (
186
- profile_dir = default_profile , cluster_id = ""
202
+ profile_dir = default_profile_dir , cluster_id = ""
187
203
).cluster_file
188
204
for i in range (100 ):
189
205
if os .path .isfile (cluster_file ) or start .poll () is not None :
@@ -197,10 +213,18 @@ def test_ipcluster_start_stop(request, ipython_dir, daemonize):
197
213
assert len (out .splitlines ()) == 2
198
214
199
215
# cluster running, try to connect with default args
200
- cluster = ipp .Cluster .from_file ()
201
- with cluster .connect_client_sync () as rc :
202
- rc .wait_for_engines (n = 2 )
203
- rc [:].apply_sync (os .getpid )
216
+ cluster = ipp .Cluster .from_file (log_level = 10 )
217
+ try :
218
+ with cluster .connect_client_sync () as rc :
219
+ rc .wait_for_engines (n = 2 , timeout = 60 )
220
+ rc [:].apply_async (os .getpid ).get (timeout = 10 )
221
+ except Exception :
222
+ print ("controller output" )
223
+ print (cluster .controller .get_output ())
224
+ print ("engine output" )
225
+ for engine_set in cluster .engines .values ():
226
+ print (engine_set .get_output ())
227
+ raise
204
228
205
229
# stop with ipcluster stop
206
230
check_call ([sys .executable , "-m" , "ipyparallel.cluster" , "stop" ])
0 commit comments