(self)
| 1243 | run(client) |
| 1244 | |
| 1245 | def test_flush_before_shutdown(self): |
| 1246 | CHUNK = 1024 * 128 |
| 1247 | SIZE = 32 |
| 1248 | |
| 1249 | sslctx = self._create_server_ssl_context( |
| 1250 | test_utils.ONLYCERT, test_utils.ONLYKEY) |
| 1251 | client_sslctx = self._create_client_ssl_context() |
| 1252 | |
| 1253 | future = None |
| 1254 | |
| 1255 | def server(sock): |
| 1256 | sock.starttls(sslctx, server_side=True) |
| 1257 | self.assertEqual(sock.recv_all(4), b'ping') |
| 1258 | sock.send(b'pong') |
| 1259 | time.sleep(0.5) # hopefully stuck the TCP buffer |
| 1260 | data = sock.recv_all(CHUNK * SIZE) |
| 1261 | self.assertEqual(len(data), CHUNK * SIZE) |
| 1262 | sock.close() |
| 1263 | |
| 1264 | def run(meth): |
| 1265 | def wrapper(sock): |
| 1266 | try: |
| 1267 | meth(sock) |
| 1268 | except Exception as ex: |
| 1269 | self.loop.call_soon_threadsafe(future.set_exception, ex) |
| 1270 | else: |
| 1271 | self.loop.call_soon_threadsafe(future.set_result, None) |
| 1272 | return wrapper |
| 1273 | |
| 1274 | async def client(addr): |
| 1275 | nonlocal future |
| 1276 | future = self.loop.create_future() |
| 1277 | reader, writer = await asyncio.open_connection( |
| 1278 | *addr, |
| 1279 | ssl=client_sslctx, |
| 1280 | server_hostname='', |
| 1281 | ssl_handshake_timeout=HANDSHAKE_TIMEOUT) |
| 1282 | sslprotocol = writer.transport._ssl_protocol |
| 1283 | writer.write(b'ping') |
| 1284 | data = await reader.readexactly(4) |
| 1285 | self.assertEqual(data, b'pong') |
| 1286 | |
| 1287 | sslprotocol.pause_writing() |
| 1288 | for _ in range(SIZE): |
| 1289 | writer.write(b'x' * CHUNK) |
| 1290 | |
| 1291 | writer.close() |
| 1292 | sslprotocol.resume_writing() |
| 1293 | |
| 1294 | await self.wait_closed(writer) |
| 1295 | try: |
| 1296 | data = await reader.read() |
| 1297 | self.assertEqual(data, b'') |
| 1298 | except ConnectionResetError: |
| 1299 | pass |
| 1300 | await future |
| 1301 | |
| 1302 | with self.tcp_server(run(server)) as srv: |
nothing calls this directly
no test coverage detected