Skip to content

Commit ef1173a

Browse files
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 46f40be) Co-authored-by: Victor Stinner <[email protected]>
1 parent 321f28c commit ef1173a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Lib/test/test_socket.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,9 +2616,18 @@ def testSendmsgTimeout(self):
26162616
def _testSendmsgTimeout(self):
26172617
try:
26182618
self.cli_sock.settimeout(0.03)
2619-
with self.assertRaises(socket.timeout):
2619+
try:
26202620
while True:
26212621
self.sendmsgToServer([b"a"*512])
2622+
except socket.timeout:
2623+
pass
2624+
except OSError as exc:
2625+
if exc.errno != errno.ENOMEM:
2626+
raise
2627+
# bpo-33937 the test randomly fails on Travis CI with
2628+
# "OSError: [Errno 12] Cannot allocate memory"
2629+
else:
2630+
self.fail("socket.timeout not raised")
26222631
finally:
26232632
self.misc_event.set()
26242633

@@ -2641,8 +2650,10 @@ def _testSendmsgDontWait(self):
26412650
with self.assertRaises(OSError) as cm:
26422651
while True:
26432652
self.sendmsgToServer([b"a"*512], [], socket.MSG_DONTWAIT)
2653+
# bpo-33937: catch also ENOMEM, the test randomly fails on Travis CI
2654+
# with "OSError: [Errno 12] Cannot allocate memory"
26442655
self.assertIn(cm.exception.errno,
2645-
(errno.EAGAIN, errno.EWOULDBLOCK))
2656+
(errno.EAGAIN, errno.EWOULDBLOCK, errno.ENOMEM))
26462657
finally:
26472658
self.misc_event.set()
26482659

0 commit comments

Comments
 (0)