Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 0f4ee8d

Browse files
committed
use cancelled error to test non-retryable methods
1 parent c560589 commit 0f4ee8d

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

google/cloud/bigtable/data/_metrics/data_model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def _parse_response_metadata_blob(blob: bytes) -> Tuple[str, str] | None:
280280
# failed to parse metadata
281281
return None
282282

283-
def end_attempt_with_status(self, status: StatusCode | Exception) -> None:
283+
def end_attempt_with_status(self, status: StatusCode | BaseException) -> None:
284284
"""
285285
Called to mark the end of an attempt for the operation.
286286
@@ -297,7 +297,7 @@ def end_attempt_with_status(self, status: StatusCode | Exception) -> None:
297297
return self._handle_error(
298298
INVALID_STATE_ERROR.format("end_attempt_with_status", self.state)
299299
)
300-
if isinstance(status, Exception):
300+
if isinstance(status, BaseException):
301301
status = self._exc_to_status(status)
302302
complete_attempt = CompletedAttemptMetric(
303303
duration_ns=time.monotonic_ns() - self.active_attempt.start_time_ns,
@@ -312,7 +312,7 @@ def end_attempt_with_status(self, status: StatusCode | Exception) -> None:
312312
for handler in self.handlers:
313313
handler.on_attempt_complete(complete_attempt, self)
314314

315-
def end_with_status(self, status: StatusCode | Exception) -> None:
315+
def end_with_status(self, status: StatusCode | BaseException) -> None:
316316
"""
317317
Called to mark the end of the operation. If there is an active attempt,
318318
end_attempt_with_status will be called with the same status.
@@ -329,7 +329,7 @@ def end_with_status(self, status: StatusCode | Exception) -> None:
329329
INVALID_STATE_ERROR.format("end_with_status", self.state)
330330
)
331331
final_status = (
332-
self._exc_to_status(status) if isinstance(status, Exception) else status
332+
self._exc_to_status(status) if isinstance(status, BaseException) else status
333333
)
334334
if self.state == OperationState.ACTIVE_ATTEMPT:
335335
self.end_attempt_with_status(final_status)
@@ -367,7 +367,7 @@ def cancel(self):
367367
handler.on_operation_cancelled(self)
368368

369369
@staticmethod
370-
def _exc_to_status(exc: Exception) -> StatusCode:
370+
def _exc_to_status(exc: BaseException) -> StatusCode:
371371
"""
372372
Extracts the grpc status code from an exception.
373373

tests/system/data/test_metrics_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,8 @@ async def test_sample_row_keys_failure_grpc(
15381538
num_retryable = 3
15391539
for i in range(num_retryable):
15401540
error_injector.push(exc)
1541-
error_injector.push(RuntimeError)
1542-
with pytest.raises(RuntimeError):
1541+
error_injector.push(asyncio.CancelledError)
1542+
with pytest.raises(asyncio.CancelledError):
15431543
await table.sample_row_keys(retryable_errors=[Aborted])
15441544
# validate counts
15451545
assert len(handler.completed_operations) == 1
@@ -1731,9 +1731,9 @@ async def test_read_modify_write_failure_grpc(
17311731
rule = IncrementRule(family, qualifier, 1)
17321732

17331733
# trigger an exception
1734-
exc = RuntimeError("injected")
1734+
exc = asyncio.CancelledError("injected")
17351735
error_injector.push(exc)
1736-
with pytest.raises(RuntimeError):
1736+
with pytest.raises(asyncio.CancelledError):
17371737
await table.read_modify_write_row(row_key, rule)
17381738

17391739
# validate counts
@@ -1904,9 +1904,9 @@ async def test_check_and_mutate_row_failure_grpc(
19041904
await temp_rows.add_row(row_key, value=1, family=family, qualifier=qualifier)
19051905

19061906
# trigger an exception
1907-
exc = RuntimeError("injected")
1907+
exc = asyncio.CancelledError("injected")
19081908
error_injector.push(exc)
1909-
with pytest.raises(RuntimeError):
1909+
with pytest.raises(asyncio.CancelledError):
19101910
await table.check_and_mutate_row(
19111911
row_key,
19121912
predicate=ValueRangeFilter(0, 2),

0 commit comments

Comments
 (0)