Skip to content

Commit 857b002

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 0b3e120 commit 857b002

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
@@ -2287,9 +2287,18 @@ def testSendmsgTimeout(self):
22872287
def _testSendmsgTimeout(self):
22882288
try:
22892289
self.cli_sock.settimeout(0.03)
2290-
with self.assertRaises(socket.timeout):
2290+
try:
22912291
while True:
22922292
self.sendmsgToServer([b"a"*512])
2293+
except socket.timeout:
2294+
pass
2295+
except OSError as exc:
2296+
if exc.errno != errno.ENOMEM:
2297+
raise
2298+
# bpo-33937 the test randomly fails on Travis CI with
2299+
# "OSError: [Errno 12] Cannot allocate memory"
2300+
else:
2301+
self.fail("socket.timeout not raised")
22932302
finally:
22942303
self.misc_event.set()
22952304

@@ -2312,8 +2321,10 @@ def _testSendmsgDontWait(self):
23122321
with self.assertRaises(OSError) as cm:
23132322
while True:
23142323
self.sendmsgToServer([b"a"*512], [], socket.MSG_DONTWAIT)
2324+
# bpo-33937: catch also ENOMEM, the test randomly fails on Travis CI
2325+
# with "OSError: [Errno 12] Cannot allocate memory"
23152326
self.assertIn(cm.exception.errno,
2316-
(errno.EAGAIN, errno.EWOULDBLOCK))
2327+
(errno.EAGAIN, errno.EWOULDBLOCK, errno.ENOMEM))
23172328
finally:
23182329
self.misc_event.set()
23192330

0 commit comments

Comments
 (0)