summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 08:10:22 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 08:10:22 +0200
commit881c423129262cd20b4de803701e2bee46fcbe81 (patch)
tree6661ba1885e794bd1c2be1fc991cb5fe600f774e
parent4c023838c0459f77e8d528ce31b2f99ff96944fc (diff)
downloadpsutil-881c423129262cd20b4de803701e2bee46fcbe81.tar.gz
finally! fix the test bug which was causing wait_for_file() to hang sometimes
-rw-r--r--psutil/tests/__init__.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index 7c14680b..47c09a87 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -91,6 +91,7 @@ __all__ = [
'install_pip', 'install_test_deps',
# fs utils
'chdir', 'safe_rmpath', 'create_exe', 'decode_path', 'encode_path',
+ 'unique_filename',
# subprocesses
'pyrun', 'reap_children', 'get_test_subprocess',
'create_proc_children_pair',
@@ -269,6 +270,7 @@ def create_proc_children_pair():
Return a (child, grandchild) tuple.
The 2 processes are fully initialized and will live for 60 secs.
"""
+ _TESTFN2 = os.path.basename(_TESTFN) + '2' # need to be relative
s = textwrap.dedent("""\
import subprocess, os, sys, time
PYTHON = os.path.realpath(sys.executable)
@@ -279,10 +281,10 @@ def create_proc_children_pair():
s += "time.sleep(60);"
subprocess.Popen([PYTHON, '-c', s])
time.sleep(60)
- """ % _TESTFN)
+ """ % _TESTFN2)
child1 = psutil.Process(pyrun(s).pid)
- data = wait_for_file(_TESTFN, delete=False, empty=False)
- os.remove(_TESTFN)
+ data = wait_for_file(_TESTFN2, delete=False, empty=False)
+ os.remove(_TESTFN2)
child2_pid = int(data)
_pids_started.add(child2_pid)
child2 = psutil.Process(child2_pid)
@@ -610,6 +612,10 @@ def create_exe(outpath, c_code=None):
os.chmod(outpath, st.st_mode | stat.S_IEXEC)
+def unique_filename(prefix=TESTFILE_PREFIX, suffix=""):
+ return tempfile.mktemp(prefix=prefix, suffix=suffix)
+
+
# ===================================================================
# --- testing
# ===================================================================
@@ -783,7 +789,7 @@ def unix_socket_path(suffix=""):
and tries to delete it on exit.
"""
assert psutil.POSIX
- path = tempfile.mktemp(prefix=TESTFILE_PREFIX, suffix=suffix)
+ path = unique_filename(suffix=suffix)
try:
yield path
finally: