11"""Test CLI application behavior"""
2+ import glob
23import json
34import os
45import sys
@@ -169,12 +170,27 @@ def test_ipcluster_list(Cluster):
169170
170171@pytest .mark .parametrize ("daemonize" , (False , True ))
171172def 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+
173187 n = 2
174188 start_args = ["-n" , str (n )]
175189 if daemonize :
176190 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+ )
178194 request .addfinalizer (start .terminate )
179195 if daemonize :
180196 # if daemonize, should exit after starting
@@ -183,7 +199,7 @@ def test_ipcluster_start_stop(request, ipython_dir, daemonize):
183199 # wait for file to appear
184200 # only need this if not daemonize
185201 cluster_file = ipp .Cluster (
186- profile_dir = default_profile , cluster_id = ""
202+ profile_dir = default_profile_dir , cluster_id = ""
187203 ).cluster_file
188204 for i in range (100 ):
189205 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):
197213 assert len (out .splitlines ()) == 2
198214
199215 # 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
204228
205229 # stop with ipcluster stop
206230 check_call ([sys .executable , "-m" , "ipyparallel.cluster" , "stop" ])
0 commit comments