(self)
| 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 |
nothing calls this directly
no test coverage detected