MCPcopy Create free account
hub / github.com/apache/arrow / test_write_error_propagation

Function test_write_error_propagation

python/pyarrow/tests/test_flight.py:2578–2645  ·  view source on GitHub ↗

Ensure that exceptions during writing preserve error context. See https://issues.apache.org/jira/browse/ARROW-16592.

()

Source from the content-addressed store, hash-verified

2576
2577@pytest.mark.slow # Takes a while for gRPC to "realize" writes fail
2578def test_write_error_propagation():
2579 """
2580 Ensure that exceptions during writing preserve error context.
2581
2582 See https://issues.apache.org/jira/browse/ARROW-16592.
2583 """
2584 expected_message = "foo"
2585 expected_info = b"bar"
2586 exc = flight.FlightCancelledError(
2587 expected_message, extra_info=expected_info)
2588 descriptor = flight.FlightDescriptor.for_command(b"")
2589 schema = pa.schema([("int64", pa.int64())])
2590
2591 class FailServer(flight.FlightServerBase):
2592 def do_put(self, context, descriptor, reader, writer):
2593 raise exc
2594
2595 def do_exchange(self, context, descriptor, reader, writer):
2596 raise exc
2597
2598 with FailServer() as server, \
2599 FlightClient(('localhost', server.port)) as client:
2600 # DoPut
2601 writer, reader = client.do_put(descriptor, schema)
2602
2603 # Set a concurrent reader - ensure this doesn't block the
2604 # writer side from calling Close()
2605 def _reader():
2606 try:
2607 while True:
2608 reader.read()
2609 except flight.FlightError:
2610 return
2611
2612 thread = threading.Thread(target=_reader, daemon=True)
2613 thread.start()
2614
2615 with pytest.raises(flight.FlightCancelledError) as exc_info:
2616 while True:
2617 writer.write_batch(pa.record_batch([[1]], schema=schema))
2618 assert exc_info.value.extra_info == expected_info
2619
2620 with pytest.raises(flight.FlightCancelledError) as exc_info:
2621 writer.close()
2622 assert exc_info.value.extra_info == expected_info
2623 thread.join()
2624
2625 # DoExchange
2626 writer, reader = client.do_exchange(descriptor)
2627
2628 def _reader():
2629 try:
2630 while True:
2631 reader.read_chunk()
2632 except flight.FlightError:
2633 return
2634
2635 thread = threading.Thread(target=_reader, daemon=True)

Callers

nothing calls this directly

Calls 9

FlightClientClass · 0.90
FailServerClass · 0.85
write_batchMethod · 0.80
schemaMethod · 0.45
do_putMethod · 0.45
startMethod · 0.45
closeMethod · 0.45
joinMethod · 0.45
do_exchangeMethod · 0.45

Tested by

no test coverage detected