Ensure that exceptions during writing preserve error context. See https://issues.apache.org/jira/browse/ARROW-16592.
()
| 2538 | |
| 2539 | @pytest.mark.slow # Takes a while for gRPC to "realize" writes fail |
| 2540 | def test_write_error_propagation(): |
| 2541 | """ |
| 2542 | Ensure that exceptions during writing preserve error context. |
| 2543 | |
| 2544 | See https://issues.apache.org/jira/browse/ARROW-16592. |
| 2545 | """ |
| 2546 | expected_message = "foo" |
| 2547 | expected_info = b"bar" |
| 2548 | exc = flight.FlightCancelledError( |
| 2549 | expected_message, extra_info=expected_info) |
| 2550 | descriptor = flight.FlightDescriptor.for_command(b"") |
| 2551 | schema = pa.schema([("int64", pa.int64())]) |
| 2552 | |
| 2553 | class FailServer(flight.FlightServerBase): |
| 2554 | def do_put(self, context, descriptor, reader, writer): |
| 2555 | raise exc |
| 2556 | |
| 2557 | def do_exchange(self, context, descriptor, reader, writer): |
| 2558 | raise exc |
| 2559 | |
| 2560 | with FailServer() as server, \ |
| 2561 | FlightClient(('localhost', server.port)) as client: |
| 2562 | # DoPut |
| 2563 | writer, reader = client.do_put(descriptor, schema) |
| 2564 | |
| 2565 | # Set a concurrent reader - ensure this doesn't block the |
| 2566 | # writer side from calling Close() |
| 2567 | def _reader(): |
| 2568 | try: |
| 2569 | while True: |
| 2570 | reader.read() |
| 2571 | except flight.FlightError: |
| 2572 | return |
| 2573 | |
| 2574 | thread = threading.Thread(target=_reader, daemon=True) |
| 2575 | thread.start() |
| 2576 | |
| 2577 | with pytest.raises(flight.FlightCancelledError) as exc_info: |
| 2578 | while True: |
| 2579 | writer.write_batch(pa.record_batch([[1]], schema=schema)) |
| 2580 | assert exc_info.value.extra_info == expected_info |
| 2581 | |
| 2582 | with pytest.raises(flight.FlightCancelledError) as exc_info: |
| 2583 | writer.close() |
| 2584 | assert exc_info.value.extra_info == expected_info |
| 2585 | thread.join() |
| 2586 | |
| 2587 | # DoExchange |
| 2588 | writer, reader = client.do_exchange(descriptor) |
| 2589 | |
| 2590 | def _reader(): |
| 2591 | try: |
| 2592 | while True: |
| 2593 | reader.read_chunk() |
| 2594 | except flight.FlightError: |
| 2595 | return |
| 2596 | |
| 2597 | thread = threading.Thread(target=_reader, daemon=True) |
nothing calls this directly
no test coverage detected