summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-15 20:09:52 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-15 20:09:52 +0200
commit2bf6c88fc3ed3b5ec9d67a9ab35d20bf2fd43d54 (patch)
tree6c9ff436ba8ab39c76f3e989bfa422df1c9b14e8
parentfd2205bad09db0efab8958c359897fc1772dc187 (diff)
downloadpsutil-2bf6c88fc3ed3b5ec9d67a9ab35d20bf2fd43d54.tar.gz
add connections tests
-rw-r--r--docs/index.rst3
-rwxr-xr-xpsutil/tests/test_connections.py46
2 files changed, 39 insertions, 10 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 4c0bb597..d6488e34 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1837,6 +1837,9 @@ Process class
pconn(fd=123, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 51314), raddr=('72.14.234.83', 443), status='SYN_SENT')]
.. note::
+ (Solaris) UNIX sockets are not supported.
+
+ .. note::
(Linux, FreeBSD) "raddr" field for UNIX sockets is always set to "".
This is a limitation of the OS.
diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py
index 906706a5..83bf1c53 100755
--- a/psutil/tests/test_connections.py
+++ b/psutil/tests/test_connections.py
@@ -31,6 +31,7 @@ from psutil.tests import AF_UNIX
from psutil.tests import bind_socket
from psutil.tests import bind_unix_socket
from psutil.tests import check_connection_ntuple
+from psutil.tests import create_sockets
from psutil.tests import get_free_port
from psutil.tests import pyrun
from psutil.tests import reap_children
@@ -352,6 +353,30 @@ class TestConnectedSocketPairs(Base, unittest.TestCase):
# err
self.assertRaises(ValueError, p.connections, kind='???')
+ def test_multi_sockets(self):
+ with create_sockets() as socks:
+ cons = thisproc.connections(kind='all')
+ self.assertEqual(len(socks), len(cons))
+ cons = thisproc.connections(kind='tcp')
+ self.assertEqual(len(cons), 2)
+ cons = thisproc.connections(kind='tcp4')
+ self.assertEqual(len(cons), 1)
+ cons = thisproc.connections(kind='tcp6')
+ self.assertEqual(len(cons), 1)
+ cons = thisproc.connections(kind='udp')
+ self.assertEqual(len(cons), 2)
+ cons = thisproc.connections(kind='udp4')
+ self.assertEqual(len(cons), 1)
+ cons = thisproc.connections(kind='udp6')
+ self.assertEqual(len(cons), 1)
+ cons = thisproc.connections(kind='inet')
+ self.assertEqual(len(cons), 4)
+ cons = thisproc.connections(kind='inet6')
+ self.assertEqual(len(cons), 2)
+ if POSIX and not SUNOS:
+ cons = thisproc.connections(kind='unix')
+ self.assertEqual(len(cons), 3)
+
# =====================================================================
# --- Miscellaneous tests
@@ -371,16 +396,17 @@ class TestSystemWideConnections(unittest.TestCase):
self.assertIn(conn.type, types_, msg=conn)
check_connection_ntuple(conn)
- from psutil._common import conn_tmap
- for kind, groups in conn_tmap.items():
- if SUNOS and kind == 'unix':
- continue
- families, types_ = groups
- cons = psutil.net_connections(kind)
- self.assertEqual(len(cons), len(set(cons)))
- check(cons, families, types_)
-
- self.assertRaises(ValueError, psutil.net_connections, kind='???')
+ with create_sockets():
+ from psutil._common import conn_tmap
+ for kind, groups in conn_tmap.items():
+ if SUNOS and kind == 'unix':
+ continue
+ families, types_ = groups
+ cons = psutil.net_connections(kind)
+ self.assertEqual(len(cons), len(set(cons)))
+ check(cons, families, types_)
+
+ self.assertRaises(ValueError, psutil.net_connections, kind='???')
# =====================================================================