From decebeb95d329f971e432d8f0bb47945c927c6bb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 25 Sep 2018 09:08:02 +0200 Subject: [PATCH] bpo-33937: Catch ENOMEM error in test_socket Fix test_socket.SendmsgSCTPStreamTest: catch ENOMEM error. testSendmsgTimeout() and testSendmsgDontWait() randomly fail on Travis CI with: "OSError: [Errno 12] Cannot allocate memory". --- Lib/test/test_socket.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index f4d58ebf7157ba6..bd4fad1f6380432 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()