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

Method test_drain_raises

Lib/test/test_asyncio/test_streams.py:888–929  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

886 self.loop.run_until_complete(main())
887
888 def test_drain_raises(self):
889 # See http://bugs.python.org/issue25441
890
891 # This test should not use asyncio for the mock server; the
892 # whole point of the test is to test for a bug in drain()
893 # where it never gives up the event loop but the socket is
894 # closed on the server side.
895
896 messages = []
897 self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
898 q = queue.Queue()
899
900 def server():
901 # Runs in a separate thread.
902 with socket.create_server(('localhost', 0)) as sock:
903 addr = sock.getsockname()
904 q.put(addr)
905 clt, _ = sock.accept()
906 clt.close()
907
908 async def client(host, port):
909 reader, writer = await asyncio.open_connection(host, port)
910
911 while True:
912 writer.write(b"foo\n")
913 await writer.drain()
914
915 # Start the server thread and wait for it to be listening.
916 thread = threading.Thread(target=server)
917 thread.daemon = True
918 thread.start()
919 addr = q.get()
920
921 # Should not be stuck in an infinite loop.
922 with self.assertRaises((ConnectionResetError, ConnectionAbortedError,
923 BrokenPipeError)):
924 self.loop.run_until_complete(client(*addr))
925
926 # Clean up the thread. (Only on success; on failure, it may
927 # be stuck in accept().)
928 thread.join()
929 self.assertEqual([], messages)
930
931 def test___repr__(self):
932 stream = asyncio.StreamReader(loop=self.loop)

Callers

nothing calls this directly

Calls 9

startMethod · 0.95
getMethod · 0.95
joinMethod · 0.95
QueueMethod · 0.80
set_exception_handlerMethod · 0.45
appendMethod · 0.45
assertRaisesMethod · 0.45
run_until_completeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected