Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
222a0aa5
Commit
222a0aa5
authored
Aug 24, 2013
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #18756: make test_urandom_failure more robust by executing its code in a subprocess
parent
515bb25f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
Lib/test/test_os.py
Lib/test/test_os.py
+19
-10
No files found.
Lib/test/test_os.py
View file @
222a0aa5
...
...
@@ -1007,17 +1007,26 @@ 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
:
# Check urandom() failing when it is not able to open /dev/random.
# We spawn a new process to make the test more robust (if getrlimit()
# failed to restore the file descriptor limit after this, the whole
# test suite would crash; this actually happened on the OS X Tiger
# buildbot).
code
=
"""if 1:
import errno
import os
import resource
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_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.EMFILE, e.errno
else:
raise AssertionError("OSError not raised")
"""
assert_python_ok
(
'-c'
,
code
)
@
contextlib
.
contextmanager
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment