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

Method test_start_tls_slow_client_cancel

Lib/test/test_asyncio/test_ssl.py:900–959  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

898 timeout=self.TIMEOUT))
899
900 def test_start_tls_slow_client_cancel(self):
901 HELLO_MSG = b'1' * self.PAYLOAD_SIZE
902
903 client_context = test_utils.simple_client_sslcontext()
904 server_waits_on_handshake = self.loop.create_future()
905
906 def serve(sock):
907 sock.settimeout(self.TIMEOUT)
908
909 data = sock.recv_all(len(HELLO_MSG))
910 self.assertEqual(len(data), len(HELLO_MSG))
911
912 try:
913 self.loop.call_soon_threadsafe(
914 server_waits_on_handshake.set_result, None)
915 data = sock.recv_all(1024 * 1024)
916 except ConnectionAbortedError:
917 pass
918 finally:
919 sock.close()
920
921 class ClientProto(asyncio.Protocol):
922 def __init__(self, on_data, on_eof):
923 self.on_data = on_data
924 self.on_eof = on_eof
925 self.con_made_cnt = 0
926
927 def connection_made(proto, tr):
928 proto.con_made_cnt += 1
929 # Ensure connection_made gets called only once.
930 self.assertEqual(proto.con_made_cnt, 1)
931
932 def data_received(self, data):
933 self.on_data.set_result(data)
934
935 def eof_received(self):
936 self.on_eof.set_result(True)
937
938 async def client(addr):
939 await asyncio.sleep(0.5)
940
941 on_data = self.loop.create_future()
942 on_eof = self.loop.create_future()
943
944 tr, proto = await self.loop.create_connection(
945 lambda: ClientProto(on_data, on_eof), *addr)
946
947 tr.write(HELLO_MSG)
948
949 await server_waits_on_handshake
950
951 with self.assertRaises(asyncio.TimeoutError):
952 await asyncio.wait_for(
953 self.loop.start_tls(tr, proto, client_context),
954 0.5)
955
956 with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
957 self.loop.run_until_complete(

Callers

nothing calls this directly

Calls 4

tcp_serverMethod · 0.95
create_futureMethod · 0.45
run_until_completeMethod · 0.45
wait_forMethod · 0.45

Tested by

no test coverage detected