(self)
| 928 | self.loop.run_until_complete(main()) |
| 929 | |
| 930 | def test_drain_raises(self): |
| 931 | # See http://bugs.python.org/issue25441 |
| 932 | |
| 933 | # This test should not use asyncio for the mock server; the |
| 934 | # whole point of the test is to test for a bug in drain() |
| 935 | # where it never gives up the event loop but the socket is |
| 936 | # closed on the server side. |
| 937 | |
| 938 | messages = [] |
| 939 | self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx)) |
| 940 | q = queue.Queue() |
| 941 | |
| 942 | def server(): |
| 943 | # Runs in a separate thread. |
| 944 | with socket.create_server(('localhost', 0)) as sock: |
| 945 | addr = sock.getsockname() |
| 946 | q.put(addr) |
| 947 | clt, _ = sock.accept() |
| 948 | clt.close() |
| 949 | |
| 950 | async def client(host, port): |
| 951 | reader, writer = await asyncio.open_connection(host, port) |
| 952 | |
| 953 | while True: |
| 954 | writer.write(b"foo\n") |
| 955 | await writer.drain() |
| 956 | |
| 957 | # Start the server thread and wait for it to be listening. |
| 958 | thread = threading.Thread(target=server) |
| 959 | thread.daemon = True |
| 960 | thread.start() |
| 961 | addr = q.get() |
| 962 | |
| 963 | # Should not be stuck in an infinite loop. |
| 964 | with self.assertRaises((ConnectionResetError, ConnectionAbortedError, |
| 965 | BrokenPipeError)): |
| 966 | self.loop.run_until_complete(client(*addr)) |
| 967 | |
| 968 | # Clean up the thread. (Only on success; on failure, it may |
| 969 | # be stuck in accept().) |
| 970 | thread.join() |
| 971 | self.assertEqual([], messages) |
| 972 | |
| 973 | def test___repr__(self): |
| 974 | stream = asyncio.StreamReader(loop=self.loop) |
nothing calls this directly
no test coverage detected