Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Delta Between Two Patch Sets: Lib/test/test_socketserver.py

Issue 26309: socketserver.BaseServer._handle_request_noblock() don't shutdwon request if verify_request is False
Left Patch Set: Created 4 years ago
Right Patch Set: Created 4 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/socketserver.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """ 1 """
2 Test suite for socketserver. 2 Test suite for socketserver.
3 """ 3 """
4 4
5 import contextlib 5 import contextlib
6 import os 6 import os
7 import select 7 import select
8 import signal 8 import signal
9 import socket 9 import socket
10 import select 10 import select
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 def test_tcpserver_bind_leak(self): 273 def test_tcpserver_bind_leak(self):
274 # Issue #22435: the server socket wouldn't be closed if bind()/listen() 274 # Issue #22435: the server socket wouldn't be closed if bind()/listen()
275 # failed. 275 # failed.
276 # Create many servers for which bind() will fail, to see if this result 276 # Create many servers for which bind() will fail, to see if this result
277 # in FD exhaustion. 277 # in FD exhaustion.
278 for i in range(1024): 278 for i in range(1024):
279 with self.assertRaises(OverflowError): 279 with self.assertRaises(OverflowError):
280 socketserver.TCPServer((HOST, -1), 280 socketserver.TCPServer((HOST, -1),
281 socketserver.StreamRequestHandler) 281 socketserver.StreamRequestHandler)
282 282
283 def test_shutdown_request_if_verify_false(self): 283 def test_shutdown_request_called_if_verify_request_false(self):
284 # Issue #26309: BaseServer should call shutdown_request even if 284 # Issue #26309: BaseServer should call shutdown_request even if
285 # verify_request is False 285 # verify_request is False
286 shutdown_called = False
287
286 class MyServer(socketserver.TCPServer): 288 class MyServer(socketserver.TCPServer):
287 def verify_request(self, request, client_address): 289 def verify_request(self, request, client_address):
288 return False 290 return False
289 291
290 def process_request(self, request, client_address):
291 socketserver.TCPServer.shutdown_request(self, request)
292
293 def shutdown_request(self, request): 292 def shutdown_request(self, request):
294 # we pass None as client_address because we don't have it and it 's okay because it's not used 293 nonlocal shutdown_called
295 self.finish_request(request, None) 294 shutdown_called = True
296 self.close_request(request) 295 super().shutdown_request(request)
296
297 def connect_to_server(proto, addr):
298 s = socket.socket(proto, socket.SOCK_STREAM)
299 s.connect(addr)
300 s.close()
297 301
298 self.run_server(MyServer, 302 self.run_server(MyServer,
299 socketserver.StreamRequestHandler, 303 socketserver.StreamRequestHandler,
300 self.stream_examine) 304 connect_to_server)
305 self.assertEqual(shutdown_called, True)
301 306
302 307
303 class MiscTestCase(unittest.TestCase): 308 class MiscTestCase(unittest.TestCase):
304 309
305 def test_all(self): 310 def test_all(self):
306 # objects defined in the module should be in __all__ 311 # objects defined in the module should be in __all__
307 expected = [] 312 expected = []
308 for name in dir(socketserver): 313 for name in dir(socketserver):
309 if not name.startswith('_'): 314 if not name.startswith('_'):
310 mod_object = getattr(socketserver, name) 315 mod_object = getattr(socketserver, name)
311 if getattr(mod_object, '__module__', None) == 'socketserver': 316 if getattr(mod_object, '__module__', None) == 'socketserver':
312 expected.append(name) 317 expected.append(name)
313 self.assertCountEqual(socketserver.__all__, expected) 318 self.assertCountEqual(socketserver.__all__, expected)
314 319
315 320
316 if __name__ == "__main__": 321 if __name__ == "__main__":
317 unittest.main() 322 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+