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

Method test_pause_reading

Lib/test/test_asyncio/test_subprocess.py:374–416  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

372 self.loop.run_until_complete(proc.wait())
373
374 def test_pause_reading(self):
375 limit = 10
376 size = (limit * 2 + 1)
377
378 async def test_pause_reading():
379 code = '\n'.join((
380 'import sys',
381 'sys.stdout.write("x" * %s)' % size,
382 'sys.stdout.flush()',
383 ))
384
385 connect_read_pipe = self.loop.connect_read_pipe
386
387 async def connect_read_pipe_mock(*args, **kw):
388 transport, protocol = await connect_read_pipe(*args, **kw)
389 transport.pause_reading = mock.Mock()
390 transport.resume_reading = mock.Mock()
391 return (transport, protocol)
392
393 self.loop.connect_read_pipe = connect_read_pipe_mock
394
395 proc = await asyncio.create_subprocess_exec(
396 sys.executable, '-c', code,
397 stdin=asyncio.subprocess.PIPE,
398 stdout=asyncio.subprocess.PIPE,
399 limit=limit,
400 )
401 stdout_transport = proc._transport.get_pipe_transport(1)
402
403 stdout, stderr = await proc.communicate()
404
405 # The child process produced more than limit bytes of output,
406 # the stream reader transport should pause the protocol to not
407 # allocate too much memory.
408 return (stdout, stdout_transport)
409
410 # Issue #22685: Ensure that the stream reader pauses the protocol
411 # when the child process produces too much data
412 stdout, transport = self.loop.run_until_complete(test_pause_reading())
413
414 self.assertEqual(stdout, b'x' * size)
415 self.assertTrue(transport.pause_reading.called)
416 self.assertTrue(transport.resume_reading.called)
417
418 def test_stdin_not_inheritable(self):
419 # asyncio issue #209: stdin must not be inheritable, otherwise

Callers

nothing calls this directly

Calls 6

assertTrueMethod · 0.80
joinMethod · 0.45
get_pipe_transportMethod · 0.45
communicateMethod · 0.45
run_until_completeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected