diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-09-25 15:49:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-25 15:49:28 (GMT) |
commit | ef1173ab141ba5387598f8859ba96f98d20d743e (patch) | |
tree | 5e88ad4feb8460948e01039f0f73022721e535f4 /Lib/test/test_socket.py | |
parent | 321f28c5f4b7361fa1b6330697b28481b4565ec8 (diff) | |
download | cpython-ef1173ab141ba5387598f8859ba96f98d20d743e.zip cpython-ef1173ab141ba5387598f8859ba96f98d20d743e.tar.gz cpython-ef1173ab141ba5387598f8859ba96f98d20d743e.tar.bz2 |
bpo-33937: Catch ENOMEM error in test_socket (GH-9557)
Fix test_socket.SendmsgSCTPStreamTest: catch ENOMEM error.
testSendmsgTimeout() and testSendmsgDontWait() randomly fail on
Travis CI with: "OSError: [Errno 12] Cannot allocate memory".
(cherry picked from commit 46f40be8b907854deb81c6132b7cb038e9e5202a)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r-- | Lib/test/test_socket.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index f4d58eb..bd4fad1 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -2616,9 +2616,18 @@ class SendmsgStreamTests(SendmsgTests): def _testSendmsgTimeout(self): try: self.cli_sock.settimeout(0.03) - with self.assertRaises(socket.timeout): + try: while True: self.sendmsgToServer([b"a"*512]) + except socket.timeout: + pass + except OSError as exc: + if exc.errno != errno.ENOMEM: + raise + # bpo-33937 the test randomly fails on Travis CI with + # "OSError: [Errno 12] Cannot allocate memory" + else: + self.fail("socket.timeout not raised") finally: self.misc_event.set() @@ -2641,8 +2650,10 @@ class SendmsgStreamTests(SendmsgTests): with self.assertRaises(OSError) as cm: while True: self.sendmsgToServer([b"a"*512], [], socket.MSG_DONTWAIT) + # bpo-33937: catch also ENOMEM, the test randomly fails on Travis CI + # with "OSError: [Errno 12] Cannot allocate memory" self.assertIn(cm.exception.errno, - (errno.EAGAIN, errno.EWOULDBLOCK)) + (errno.EAGAIN, errno.EWOULDBLOCK, errno.ENOMEM)) finally: self.misc_event.set() |