Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(65080)

Unified Diff: Lib/test/test_os.py

Issue 18756: os.urandom() fails under high load
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1020,17 +1020,23 @@ class URandomTests(unittest.TestCase):
@unittest.skipUnless(resource, "test requires the resource module")
def test_urandom_failure(self):
- soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
- resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_limit))
- try:
- with self.assertRaises(OSError) as cm:
+ # Spawn a new process to avoid breaking urandom() for the rest
+ # of the process' lifetime.
+ code = """if 1:
+ import errno
+ import os
+ import resource
+
+ soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
+ os.closerange(3, soft_limit)
+ try:
os.urandom(16)
- self.assertEqual(cm.exception.errno, errno.EMFILE)
- finally:
- # We restore the old limit as soon as possible. If doing it
- # using addCleanup(), code running in between would fail
- # creating any file descriptor.
- resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit))
+ except OSError as e:
+ assert e.errno == errno.EBADF, e.errno
+ else:
+ raise AssertionError("OSError not raised")
+ """
+ assert_python_ok('-c', code)
@contextlib.contextmanager

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+