Skip to content

Commit

Permalink
unix files on OSX cann't be deleted due to perm err
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Oct 12, 2016
1 parent e439fca commit c2670aa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions psutil/tests/test_process.py
Expand Up @@ -1044,18 +1044,18 @@ def check_conn(proc, conn, family, type, laddr, raddr, status, kinds):
@skip_on_access_denied(only_if=OSX)
def test_connections_unix(self):
def check(type):
safe_rmpath(TESTFN)
tfile = tempfile.mktemp(prefix=TESTFILE_PREFIX) if OSX else TESTFN
sock = socket.socket(AF_UNIX, type)
with contextlib.closing(sock):
sock.bind(TESTFN)
sock.bind(tfile)
cons = psutil.Process().connections(kind='unix')
conn = cons[0]
check_connection_ntuple(conn)
if conn.fd != -1: # != sunos and windows
self.assertEqual(conn.fd, sock.fileno())
self.assertEqual(conn.family, AF_UNIX)
self.assertEqual(conn.type, type)
self.assertEqual(conn.laddr, TESTFN)
self.assertEqual(conn.laddr, tfile)
if not SUNOS:
# XXX Solaris can't retrieve system-wide UNIX
# sockets.
Expand Down Expand Up @@ -1308,6 +1308,7 @@ def succeed_or_zombie_p_exc(fun, *args, **kwargs):
# Both of them are supposed to be freed / killed by
# reap_children() as they are attributable to 'us'
# (os.getpid()) via children(recursive=True).
unix_file = tempfile.mktemp(prefix=TESTFILE_PREFIX) if OSX else TESTFN
src = textwrap.dedent("""\
import os, sys, time, socket, contextlib
child_pid = os.fork()
Expand All @@ -1323,11 +1324,11 @@ def succeed_or_zombie_p_exc(fun, *args, **kwargs):
else:
pid = bytes(str(os.getpid()), 'ascii')
s.sendall(pid)
""" % TESTFN)
""" % unix_file)
with contextlib.closing(socket.socket(socket.AF_UNIX)) as sock:
try:
sock.settimeout(GLOBAL_TIMEOUT)
sock.bind(TESTFN)
sock.bind(unix_file)
sock.listen(1)
pyrun(src)
conn, _ = sock.accept()
Expand Down

0 comments on commit c2670aa

Please sign in to comment.