async def test_client(addr): fut = asyncio.Future(loop=self.loop) def prog(): try: yield tb.starttls(client_sslctx) yield tb.connect(addr) yield tb.write(A_DATA) data = yield tb.read(2) self.assertEqual(data, b'OK') yield tb.write(B_DATA) data = yield tb.read(4) self.assertEqual(data, b'SPAM') yield tb.close() except Exception as ex: self.loop.call_soon_threadsafe(fut.set_exception, ex) else: self.loop.call_soon_threadsafe(fut.set_result, None) client = tb.tcp_client(prog) client.start() clients.append(client) await fut
async def test_client(addr): fut = asyncio.Future(loop=self.loop) def prog(): try: yield tb.starttls(client_sslctx) yield tb.connect(addr) yield tb.write(A_DATA) data = yield tb.read(2) self.assertEqual(data, b'OK') yield tb.write(B_DATA) data = yield tb.read(4) self.assertEqual(data, b'SPAM') yield tb.close() except Exception as ex: self.loop.call_soon_threadsafe(fut.set_exception, ex) else: self.loop.call_soon_threadsafe(fut.set_result, None) client = tb.tcp_client(prog, family=socket.AF_UNIX) client.start() clients.append(client) await fut