MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_handshake_timeout

Method test_handshake_timeout

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

Source from the content-addressed store, hash-verified

3759 s.close()
3760
3761 def test_handshake_timeout(self):
3762 # Issue #5103: SSL handshake must respect the socket timeout
3763 server = socket.socket(socket.AF_INET)
3764 host = "127.0.0.1"
3765 port = socket_helper.bind_port(server)
3766 started = threading.Event()
3767 finish = False
3768
3769 def serve():
3770 server.listen()
3771 started.set()
3772 conns = []
3773 while not finish:
3774 r, w, e = select.select([server], [], [], 0.1)
3775 if server in r:
3776 # Let the socket hang around rather than having
3777 # it closed by garbage collection.
3778 conns.append(server.accept()[0])
3779 for sock in conns:
3780 sock.close()
3781
3782 t = threading.Thread(target=serve)
3783 t.start()
3784 started.wait()
3785
3786 try:
3787 try:
3788 c = socket.socket(socket.AF_INET)
3789 c.settimeout(0.2)
3790 c.connect((host, port))
3791 # Will attempt handshake and time out
3792 self.assertRaisesRegex(TimeoutError, "timed out",
3793 test_wrap_socket, c)
3794 finally:
3795 c.close()
3796 try:
3797 c = socket.socket(socket.AF_INET)
3798 c = test_wrap_socket(c)
3799 c.settimeout(0.2)
3800 # Will attempt handshake and time out
3801 self.assertRaisesRegex(TimeoutError, "timed out",
3802 c.connect, (host, port))
3803 finally:
3804 c.close()
3805 finally:
3806 finish = True
3807 t.join()
3808 server.close()
3809
3810 def test_server_accept(self):
3811 # 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