(self)
| 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) |
nothing calls this directly
no test coverage detected