Ensure that separate threads can read/write on a DoPut.
()
| 2060 | |
| 2061 | |
| 2062 | def test_do_put_independent_read_write(): |
| 2063 | """Ensure that separate threads can read/write on a DoPut.""" |
| 2064 | # ARROW-6063: previously this would cause gRPC to abort when the |
| 2065 | # writer was closed (due to simultaneous reads), or would hang |
| 2066 | # forever. |
| 2067 | data = [ |
| 2068 | pa.array([-10, -5, 0, 5, 10]) |
| 2069 | ] |
| 2070 | table = pa.Table.from_arrays(data, names=['a']) |
| 2071 | |
| 2072 | with MetadataFlightServer() as server, \ |
| 2073 | FlightClient(('localhost', server.port)) as client: |
| 2074 | writer, metadata_reader = client.do_put( |
| 2075 | flight.FlightDescriptor.for_path(''), |
| 2076 | table.schema) |
| 2077 | |
| 2078 | count = [0] |
| 2079 | |
| 2080 | def _reader_thread(): |
| 2081 | while metadata_reader.read() is not None: |
| 2082 | count[0] += 1 |
| 2083 | |
| 2084 | thread = threading.Thread(target=_reader_thread) |
| 2085 | thread.start() |
| 2086 | |
| 2087 | batches = table.to_batches(max_chunksize=1) |
| 2088 | with writer: |
| 2089 | for idx, batch in enumerate(batches): |
| 2090 | metadata = struct.pack('<i', idx) |
| 2091 | writer.write_with_metadata(batch, metadata) |
| 2092 | # Causes the server to stop writing and end the call |
| 2093 | writer.done_writing() |
| 2094 | # Thus reader thread will break out of loop |
| 2095 | thread.join() |
| 2096 | # writer.close() won't segfault since reader thread has |
| 2097 | # stopped |
| 2098 | assert count[0] == len(batches) |
| 2099 | |
| 2100 | |
| 2101 | def test_server_middleware_same_thread(): |
nothing calls this directly
no test coverage detected