diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-16 13:19:23 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-16 13:19:23 +0200 |
commit | ec3e2efea85b95c42ab3eb497337e6e597e0f9b6 (patch) | |
tree | 99cd5c251301b6ed943fcb834d4d7e085f1a5c71 | |
parent | 029711d94d684cb92985666f91ecbd0889218e76 (diff) | |
download | psutil-ec3e2efea85b95c42ab3eb497337e6e597e0f9b6.tar.gz |
add another test case which exposes #1013
-rwxr-xr-x | psutil/tests/test_connections.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py index 8de7e17b..4ad68a4e 100755 --- a/psutil/tests/test_connections.py +++ b/psutil/tests/test_connections.py @@ -415,6 +415,36 @@ class TestSystemWideConnections(unittest.TestCase): if x.pid == os.getpid()] self.assertEqual(len(socks), len(cons)) + def test_multi_sockets_procs(self): + # Creates multiple sub processes, each creating different + # sockets. For each process check that proc.connections() + # and net_connections() return the same results. + # This is done mainly to check whether net_connections()'s + # pid is properly set, see: + # https://github.com/giampaolo/psutil/issues/1013 + with create_sockets() as socks: + expected = len(socks) + pids = [] + src = textwrap.dedent("""\ + import time + from psutil.tests import create_sockets + with create_sockets(): + open('%s', 'w').close() + time.sleep(60) + """ % TESTFN) + for x in range(10): + sproc = pyrun(src) + wait_for_file(TESTFN, empty=True) + pids.append(sproc.pid) + + syscons = [x for x in psutil.net_connections(kind='all') if x.pid + in pids] + for pid in pids: + p = psutil.Process(pid) + self.assertEqual(len(p.connections('all')), expected) + self.assertEqual(len([x for x in syscons if x.pid == pid]), + expected) + # ===================================================================== # --- Miscellaneous tests |