[Python-checkins] bpo-33937: Catch ENOMEM error in test_socket (GH-9557)

Miss Islington (bot) webhook-mailer at python.org
Tue Sep 25 11:49:36 EDT 2018


https://github.com/python/cpython/commit/ef1173ab141ba5387598f8859ba96f98d20d743e
commit: ef1173ab141ba5387598f8859ba96f98d20d743e
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-09-25T08:49:28-07:00
summary:

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 at redhat.com>

files:
M Lib/test/test_socket.py

diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index f4d58ebf7157..bd4fad1f6380 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -2616,9 +2616,18 @@ def testSendmsgTimeout(self):
     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 @@ def _testSendmsgDontWait(self):
             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()
 



More information about the Python-checkins mailing list