diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-02-19 02:16:42 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-02-19 02:16:42 (GMT) |
commit | 63d1f47b491f60fabc328f0c8b6056b0838c015b (patch) | |
tree | b737c385a35b6d7747e557b4bf2442deaf49e8cb /Lib | |
parent | ba8474b77dd86d8dde40eaa7a4a6715a476d6242 (diff) | |
download | cpython-63d1f47b491f60fabc328f0c8b6056b0838c015b.zip cpython-63d1f47b491f60fabc328f0c8b6056b0838c015b.tar.gz cpython-63d1f47b491f60fabc328f0c8b6056b0838c015b.tar.bz2 |
Issue #26309: Rewrite test in main thread and avoid race condition
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_socketserver.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index 73754c6..2550290 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -326,28 +326,29 @@ class SocketServerTest(unittest.TestCase): SocketServer.TCPServer((HOST, -1), SocketServer.StreamRequestHandler) + +class MiscTestCase(unittest.TestCase): + def test_shutdown_request_called_if_verify_request_false(self): # Issue #26309: BaseServer should call shutdown_request even if # verify_request is False - result = {"shutdown_called": False} class MyServer(SocketServer.TCPServer): def verify_request(self, request, client_address): return False + shutdown_called = 0 def shutdown_request(self, request): - result["shutdown_called"] = True + self.shutdown_called += 1 SocketServer.TCPServer.shutdown_request(self, request) - def connect_to_server(proto, addr): - s = socket.socket(proto, socket.SOCK_STREAM) - s.connect(addr) - s.close() - - self.run_server(MyServer, - SocketServer.StreamRequestHandler, - connect_to_server) - self.assertEqual(result["shutdown_called"], True) + server = MyServer((HOST, 0), SocketServer.StreamRequestHandler) + s = socket.socket(server.address_family, socket.SOCK_STREAM) + s.connect(server.server_address) + s.close() + server.handle_request() + self.assertEqual(server.shutdown_called, 1) + server.server_close() def test_main(): |