MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_create_server_ssl_1

Method test_create_server_ssl_1

Lib/test/test_asyncio/test_ssl.py:199–292  ·  view source on GitHub ↗
(self, size)

Source from the content-addressed store, hash-verified

197
198 @support.bigmemtest(size=25, memuse=90*2**20, dry_run=False)
199 def test_create_server_ssl_1(self, size):
200 CNT = 0 # number of clients that were successful
201 TOTAL_CNT = size # total number of clients that test will create
202 TIMEOUT = support.LONG_TIMEOUT # timeout for this test
203
204 A_DATA = b'A' * 1024 * BUF_MULTIPLIER
205 B_DATA = b'B' * 1024 * BUF_MULTIPLIER
206
207 sslctx = self._create_server_ssl_context(
208 test_utils.ONLYCERT, test_utils.ONLYKEY
209 )
210 client_sslctx = self._create_client_ssl_context()
211
212 clients = []
213
214 async def handle_client(reader, writer):
215 nonlocal CNT
216
217 data = await reader.readexactly(len(A_DATA))
218 self.assertEqual(data, A_DATA)
219 writer.write(b'OK')
220
221 data = await reader.readexactly(len(B_DATA))
222 self.assertEqual(data, B_DATA)
223 writer.writelines([b'SP', bytearray(b'A'), memoryview(b'M')])
224
225 await writer.drain()
226 writer.close()
227
228 CNT += 1
229
230 async def test_client(addr):
231 fut = asyncio.Future()
232
233 def prog(sock):
234 try:
235 sock.starttls(client_sslctx)
236 sock.connect(addr)
237 sock.send(A_DATA)
238
239 data = sock.recv_all(2)
240 self.assertEqual(data, b'OK')
241
242 sock.send(B_DATA)
243 data = sock.recv_all(4)
244 self.assertEqual(data, b'SPAM')
245
246 sock.close()
247
248 except Exception as ex:
249 self.loop.call_soon_threadsafe(fut.set_exception, ex)
250 else:
251 self.loop.call_soon_threadsafe(fut.set_result, None)
252
253 client = self.tcp_client(prog)
254 client.start()
255 clients.append(client)
256

Callers

nothing calls this directly

Calls 7

start_serverFunction · 0.85
run_until_completeMethod · 0.45
assertEqualMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected