()
| 2439 | |
| 2440 | @pytest.mark.threading |
| 2441 | def test_interrupt(): |
| 2442 | if threading.current_thread().ident != threading.main_thread().ident: |
| 2443 | pytest.skip("test only works from main Python thread") |
| 2444 | |
| 2445 | def signal_from_thread(): |
| 2446 | time.sleep(0.5) |
| 2447 | signal.raise_signal(signal.SIGINT) |
| 2448 | |
| 2449 | exc_types = (KeyboardInterrupt, pa.ArrowCancelled) |
| 2450 | |
| 2451 | def test(read_all): |
| 2452 | try: |
| 2453 | try: |
| 2454 | t = threading.Thread(target=signal_from_thread) |
| 2455 | with pytest.raises(exc_types) as exc_info: |
| 2456 | t.start() |
| 2457 | read_all() |
| 2458 | finally: |
| 2459 | t.join() |
| 2460 | except KeyboardInterrupt: |
| 2461 | # In case KeyboardInterrupt didn't interrupt read_all |
| 2462 | # above, at least prevent it from stopping the test suite |
| 2463 | pytest.fail("KeyboardInterrupt didn't interrupt Flight read_all") |
| 2464 | # __context__ is sometimes None |
| 2465 | e = exc_info.value |
| 2466 | assert isinstance(e, (pa.ArrowCancelled, KeyboardInterrupt)) or \ |
| 2467 | isinstance(e.__context__, (pa.ArrowCancelled, KeyboardInterrupt)) |
| 2468 | |
| 2469 | with CancelFlightServer() as server, \ |
| 2470 | FlightClient(("localhost", server.port)) as client: |
| 2471 | |
| 2472 | reader = client.do_get(flight.Ticket(b"")) |
| 2473 | test(reader.read_all) |
| 2474 | |
| 2475 | descriptor = flight.FlightDescriptor.for_command(b"echo") |
| 2476 | writer, reader = client.do_exchange(descriptor) |
| 2477 | test(reader.read_all) |
| 2478 | try: |
| 2479 | writer.close() |
| 2480 | except (KeyboardInterrupt, flight.FlightCancelledError): |
| 2481 | # Silence the Cancelled/Interrupt exception |
| 2482 | pass |
| 2483 | |
| 2484 | |
| 2485 | def test_never_sends_data(): |
nothing calls this directly
no test coverage detected