@@ -111,7 +111,7 @@ async def test_pool_exhaustion_under_load(self, mock_session):
111111 ---------------
112112 1. Pool has finite connection limit
113113 2. Excess queries fail with NoConnectionsAvailable
114- 3. Failures are wrapped in QueryError
114+ 3. Exceptions passed through directly
115115 4. Success/failure count matches pool size
116116
117117 Why this matters:
@@ -121,8 +121,8 @@ async def test_pool_exhaustion_under_load(self, mock_session):
121121 - Database has connection limits
122122 - Pool size must be tuned
123123
124- Applications must handle pool exhaustion
125- gracefully with retries or backoff .
124+ Applications need direct access to
125+ handle pool exhaustion with retries .
126126 """
127127 async_session = AsyncCassandraSession (mock_session )
128128
@@ -152,14 +152,8 @@ def execute_async_side_effect(*args, **kwargs):
152152
153153 # First pool_size queries should succeed
154154 successful = [r for r in results if not isinstance (r , Exception )]
155- # NoConnectionsAvailable is wrapped in QueryError
156- from async_cassandra .exceptions import QueryError
157-
158- failed = [
159- r
160- for r in results
161- if isinstance (r , QueryError ) and isinstance (r .cause , NoConnectionsAvailable )
162- ]
155+ # NoConnectionsAvailable is now passed through directly
156+ failed = [r for r in results if isinstance (r , NoConnectionsAvailable )]
163157
164158 assert len (successful ) == pool_size
165159 assert len (failed ) == 3
@@ -240,12 +234,9 @@ def execute_async_side_effect(*args, **kwargs):
240234 mock_session .execute_async .side_effect = execute_async_side_effect
241235
242236 # First attempts fail
243- from async_cassandra .exceptions import QueryError
244-
245237 for i in range (3 ):
246- with pytest .raises (QueryError ) as exc_info :
238+ with pytest .raises (NoConnectionsAvailable ) :
247239 await async_session .execute ("SELECT * FROM test" )
248- assert isinstance (exc_info .value .cause , NoConnectionsAvailable )
249240
250241 # Wait a bit (simulating pool recovery)
251242 await asyncio .sleep (0.1 )
@@ -301,7 +292,7 @@ def execute_async_side_effect(*args, **kwargs):
301292 try :
302293 result = await async_session .execute (f"SELECT { i } " )
303294 results .append (result )
304- except Exception : # QueryError wrapping NoConnectionsAvailable
295+ except NoConnectionsAvailable : # NoConnectionsAvailable is now passed through directly
305296 results .append (None )
306297
307298 # Should have 1 failure (3rd query)
@@ -381,14 +372,8 @@ def execute_async_side_effect(*args, **kwargs):
381372 results = await asyncio .gather (* tasks , return_exceptions = True )
382373
383374 # Should have mix of successes and failures
384- from async_cassandra .exceptions import QueryError
385-
386375 successes = sum (1 for r in results if not isinstance (r , Exception ))
387- failures = sum (
388- 1
389- for r in results
390- if isinstance (r , QueryError ) and isinstance (r .cause , NoConnectionsAvailable )
391- )
376+ failures = sum (1 for r in results if isinstance (r , NoConnectionsAvailable ))
392377
393378 assert successes >= max_concurrent
394379 assert failures > 0
@@ -629,11 +614,8 @@ def execute_async_side_effect(*args, **kwargs):
629614 degradation_active = True
630615
631616 # Non-critical query should fail
632- from async_cassandra .exceptions import QueryError
633-
634- with pytest .raises (QueryError ) as exc_info :
617+ with pytest .raises (NoConnectionsAvailable ):
635618 await async_session .execute ("SELECT * FROM test" )
636- assert isinstance (exc_info .value .cause , NoConnectionsAvailable )
637619
638620 # Critical query should still work
639621 result = await async_session .execute ("CRITICAL: SELECT * FROM system.local" )
0 commit comments