summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-02-19 02:16:42 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-02-19 02:16:42 (GMT)
commit4bf427495fc65f331ae11903b57f6aa712a35ee3 (patch)
tree15a746f0016e0674f9f86af0a81c9da88d66d82d /Lib
parent3fe64d0c5ca5f1dc9723b9ef436d033f390b19f0 (diff)
downloadcpython-4bf427495fc65f331ae11903b57f6aa712a35ee3.zip
cpython-4bf427495fc65f331ae11903b57f6aa712a35ee3.tar.gz
cpython-4bf427495fc65f331ae11903b57f6aa712a35ee3.tar.bz2
Issue #26309: Rewrite test in main thread and avoid race condition
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socketserver.py45
1 files changed, 21 insertions, 24 deletions
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
index f8f7762..dc23210 100644
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -280,30 +280,6 @@ class SocketServerTest(unittest.TestCase):
socketserver.TCPServer((HOST, -1),
socketserver.StreamRequestHandler)
- def test_shutdown_request_called_if_verify_request_false(self):
- # Issue #26309: BaseServer should call shutdown_request even if
- # verify_request is False
- shutdown_called = False
-
- class MyServer(socketserver.TCPServer):
- def verify_request(self, request, client_address):
- return False
-
- def shutdown_request(self, request):
- nonlocal shutdown_called
- shutdown_called = True
- super().shutdown_request(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(shutdown_called, True)
-
class MiscTestCase(unittest.TestCase):
@@ -317,6 +293,27 @@ class MiscTestCase(unittest.TestCase):
expected.append(name)
self.assertCountEqual(socketserver.__all__, expected)
+ def test_shutdown_request_called_if_verify_request_false(self):
+ # Issue #26309: BaseServer should call shutdown_request even if
+ # verify_request is False
+
+ class MyServer(socketserver.TCPServer):
+ def verify_request(self, request, client_address):
+ return False
+
+ shutdown_called = 0
+ def shutdown_request(self, request):
+ self.shutdown_called += 1
+ socketserver.TCPServer.shutdown_request(self, request)
+
+ 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()
+
if __name__ == "__main__":
unittest.main()