MCPcopy Index your code
hub / github.com/python/cpython / test_handshake_timeout

Method test_handshake_timeout

Lib/test/test_ssl.py:4044–4091  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4042 s.close()
4043
4044 def test_handshake_timeout(self):
4045 # Issue #5103: SSL handshake must respect the socket timeout
4046 server = socket.socket(socket.AF_INET)
4047 host = "127.0.0.1"
4048 port = socket_helper.bind_port(server)
4049 started = threading.Event()
4050 finish = False
4051
4052 def serve():
4053 server.listen()
4054 started.set()
4055 conns = []
4056 while not finish:
4057 r, w, e = select.select([server], [], [], 0.1)
4058 if server in r:
4059 # Let the socket hang around rather than having
4060 # it closed by garbage collection.
4061 conns.append(server.accept()[0])
4062 for sock in conns:
4063 sock.close()
4064
4065 t = threading.Thread(target=serve)
4066 t.start()
4067 started.wait()
4068
4069 try:
4070 try:
4071 c = socket.socket(socket.AF_INET)
4072 c.settimeout(0.2)
4073 c.connect((host, port))
4074 # Will attempt handshake and time out
4075 self.assertRaisesRegex(TimeoutError, "timed out",
4076 test_wrap_socket, c)
4077 finally:
4078 c.close()
4079 try:
4080 c = socket.socket(socket.AF_INET)
4081 c = test_wrap_socket(c)
4082 c.settimeout(0.2)
4083 # Will attempt handshake and time out
4084 self.assertRaisesRegex(TimeoutError, "timed out",
4085 c.connect, (host, port))
4086 finally:
4087 c.close()
4088 finally:
4089 finish = True
4090 t.join()
4091 server.close()
4092
4093 def test_server_accept(self):
4094 # Issue #16357: accept() on a SSLSocket created through

Callers

nothing calls this directly

Calls 10

startMethod · 0.95
waitMethod · 0.95
joinMethod · 0.95
test_wrap_socketFunction · 0.85
socketMethod · 0.80
EventMethod · 0.80
assertRaisesRegexMethod · 0.80
settimeoutMethod · 0.45
connectMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected