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

Method test_shutdown_cleanly

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

Source from the content-addressed store, hash-verified

1180 client.stop()
1181
1182 def test_shutdown_cleanly(self):
1183 CNT = 0
1184 TOTAL_CNT = 25
1185
1186 A_DATA = b'A' * 1024 * BUF_MULTIPLIER
1187
1188 sslctx = self._create_server_ssl_context(
1189 test_utils.ONLYCERT, test_utils.ONLYKEY)
1190 client_sslctx = self._create_client_ssl_context()
1191
1192 def server(sock):
1193 sock.starttls(
1194 sslctx,
1195 server_side=True)
1196
1197 data = sock.recv_all(len(A_DATA))
1198 self.assertEqual(data, A_DATA)
1199 sock.send(b'OK')
1200
1201 sock.unwrap()
1202
1203 sock.close()
1204
1205 async def client(addr):
1206 reader, writer = await asyncio.open_connection(
1207 *addr,
1208 ssl=client_sslctx,
1209 server_hostname='',
1210 ssl_handshake_timeout=HANDSHAKE_TIMEOUT)
1211
1212 writer.write(A_DATA)
1213 self.assertEqual(await reader.readexactly(2), b'OK')
1214
1215 self.assertEqual(await reader.read(), b'')
1216
1217 nonlocal CNT
1218 CNT += 1
1219
1220 writer.close()
1221 await self.wait_closed(writer)
1222
1223 def run(coro):
1224 nonlocal CNT
1225 CNT = 0
1226
1227 async def _gather(*tasks):
1228 return await asyncio.gather(*tasks)
1229
1230 with self.tcp_server(server,
1231 max_clients=TOTAL_CNT,
1232 backlog=TOTAL_CNT) as srv:
1233 tasks = []
1234 for _ in range(TOTAL_CNT):
1235 tasks.append(coro(srv.addr))
1236
1237 self.loop.run_until_complete(
1238 _gather(*tasks))
1239

Callers

nothing calls this directly

Calls 4

runFunction · 0.50

Tested by

no test coverage detected