@@ -45,7 +45,8 @@ class _FakeUrllib3Response(io.RawIOBase):
4545
4646 pyarrow.ipc.open_stream wants a real file-like object (it checks
4747 ``closed`` and ``readable()``); the SDK's RESTResponse needs ``status``,
48- ``reason``, ``data``, and ``headers``. release_conn is recorded.
48+ ``reason``, ``data``, and ``headers``. drain_conn / release_conn are
49+ recorded so tests can assert the connection is drained before reuse.
4950 """
5051
5152 def __init__ (self , status : int , body : bytes , headers : Dict [str , str ]):
@@ -56,6 +57,7 @@ def __init__(self, status: int, body: bytes, headers: Dict[str, str]):
5657 self ._buf = io .BytesIO (body )
5758 self .headers = headers
5859 self .release_conn_called = False
60+ self .drain_conn_called = False
5961
6062 @property
6163 def data (self ) -> bytes :
@@ -71,6 +73,9 @@ def read(self, amt: Optional[int] = -1) -> bytes:
7173 def readable (self ) -> bool :
7274 return True
7375
76+ def drain_conn (self ) -> None :
77+ self .drain_conn_called = True
78+
7479 def release_conn (self ) -> None :
7580 self .release_conn_called = True
7681
@@ -146,6 +151,9 @@ def test_get_result_arrow_returns_table(monkeypatch: pytest.MonkeyPatch) -> None
146151 got = results .get_result_arrow ("res_123" )
147152
148153 assert got .equals (table )
154+ # Connection is drained (not just released) so a partially-read body can't
155+ # poison the pool and break the next request with ResponseNotReady.
156+ assert fake .drain_conn_called
149157 assert fake .release_conn_called
150158
151159 # Single request was made.
@@ -197,7 +205,8 @@ def test_stream_result_arrow_yields_reader(
197205 roundtrip = pa .Table .from_batches (batches , schema = reader .schema )
198206 assert roundtrip .equals (table )
199207
200- # Connection is released after the context exits.
208+ # Connection is drained and released after the context exits.
209+ assert fake .drain_conn_called
201210 assert fake .release_conn_called
202211
203212
0 commit comments