summaryrefslogtreecommitdiff
path: root/psutil/tests/test_process.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2018-12-13 15:54:37 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2018-12-13 15:54:37 +0100
commit2cdf81db322822ba8fb23ed67523aacb6539da95 (patch)
treeee946d6f3200eafd2dafdee78e68c899426ebf8e /psutil/tests/test_process.py
parent8351fa4ff642d997cd478a7d216b661e62a5f696 (diff)
downloadpsutil-2cdf81db322822ba8fb23ed67523aacb6539da95.tar.gz
#1373: different approach to oneshot() cache (pass Process instances around - which is faster)
Diffstat (limited to 'psutil/tests/test_process.py')
-rwxr-xr-xpsutil/tests/test_process.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index 2126e32a..cd72be85 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -1195,6 +1195,21 @@ class TestProcess(unittest.TestCase):
p.cpu_times()
self.assertEqual(m.call_count, 2)
+ def test_oneshot_cache(self):
+ # Make sure oneshot() cache is nonglobal. Instead it's
+ # supposed to be bound to the Process instance, see:
+ # https://github.com/giampaolo/psutil/issues/1373
+ p1, p2 = create_proc_children_pair()
+ p1_ppid = p1.ppid()
+ p2_ppid = p2.ppid()
+ self.assertNotEqual(p1_ppid, p2_ppid)
+ with p1.oneshot():
+ self.assertEqual(p1.ppid(), p1_ppid)
+ self.assertEqual(p2.ppid(), p2_ppid)
+ with p2.oneshot():
+ self.assertEqual(p1.ppid(), p1_ppid)
+ self.assertEqual(p2.ppid(), p2_ppid)
+
def test_halfway_terminated_process(self):
# Test that NoSuchProcess exception gets raised in case the
# process dies after we create the Process object.