Skip to content

Commit 242903a

Browse files
authored
Merge pull request #543 from minrk/debug-windows
better debugging/timeouts in test_ipcluster_start_stop
2 parents 9fb4c67 + 4d1c8c4 commit 242903a

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

ipyparallel/tests/test_apps.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test CLI application behavior"""
2+
import glob
23
import json
34
import os
45
import sys
@@ -169,12 +170,27 @@ def test_ipcluster_list(Cluster):
169170

170171
@pytest.mark.parametrize("daemonize", (False, True))
171172
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+
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

Comments
 (0)