summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-02-10 00:24:43 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2016-02-10 00:24:43 +0100
commitef78ca9454ef949a17c26ad9fc87404bb711498a (patch)
treee4d48b10d214650a52e8b291f61a23de105b382b
parenteeac8ff50e8c78f769d8d70a1591724834422f06 (diff)
downloadpsutil-ef78ca9454ef949a17c26ad9fc87404bb711498a.tar.gz
add mocked test for linux
-rw-r--r--psutil/tests/test_linux.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index d4851462..da48d08c 100644
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -698,6 +698,25 @@ class TestProcess(unittest.TestCase):
self.assertEqual(psutil.Process().exe(), "/home/foo")
self.assertEqual(psutil.Process().cwd(), "/home/foo")
+ def test_threads_mocked(self):
+ # Test the case where os.listdir() returns a file (thread)
+ # which no longer exists by the time we open() it (race
+ # condition). threads() is supposed to ignore that instead
+ # of raising NSP.
+ def open_mock(name, *args):
+ if name.startswith('/proc/%s/task' % os.getpid()):
+ raise OSError(errno.ENOENT, "")
+ else:
+ return orig_open(name, *args)
+ return orig_open(name, *args)
+
+ orig_open = open
+ patch_point = 'builtins.open' if PY3 else '__builtin__.open'
+ with mock.patch(patch_point, side_effect=open_mock) as m:
+ ret = psutil.Process().threads()
+ assert m.called
+ self.assertEqual(ret, [])
+
if __name__ == '__main__':
run_test_module_by_name(__file__)