diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asynchat.py | 2 | ||||
-rw-r--r-- | Lib/test/test_asynchat.py | 17 |
2 files changed, 19 insertions, 0 deletions
diff --git a/Lib/asynchat.py b/Lib/asynchat.py index 6e16891..14c152f 100644 --- a/Lib/asynchat.py +++ b/Lib/asynchat.py @@ -115,6 +115,8 @@ class async_chat(asyncore.dispatcher): try: data = self.recv(self.ac_in_buffer_size) + except BlockingIOError: + return except OSError as why: self.handle_error() return diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py index 84867ec..2dc9d0c 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -7,10 +7,12 @@ thread = support.import_module('_thread') import asynchat import asyncore +import errno import socket import sys import time import unittest +import unittest.mock try: import threading except ImportError: @@ -273,6 +275,21 @@ class TestAsynchat_WithPoll(TestAsynchat): usepoll = True +class TestAsynchatMocked(unittest.TestCase): + def test_blockingioerror(self): + # Issue #16133: handle_read() must ignore BlockingIOError + sock = unittest.mock.Mock() + sock.recv.side_effect = BlockingIOError(errno.EAGAIN) + + dispatcher = asynchat.async_chat() + dispatcher.set_socket(sock) + self.addCleanup(dispatcher.del_channel) + + with unittest.mock.patch.object(dispatcher, 'handle_error') as error: + dispatcher.handle_read() + self.assertFalse(error.called) + + class TestHelperFunctions(unittest.TestCase): def test_find_prefix_at_end(self): self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1) |