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

Commit 0340fce

Browse files
committed
fixed tests
1 parent 88644b2 commit 0340fce

4 files changed

Lines changed: 41 additions & 48 deletions

File tree

tests/system/data/test_metrics_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ async def test_read_rows_stream_failure_unauthorized_with_retries(
620620
# validate attempts
621621
for attempt in handler.completed_attempts:
622622
assert isinstance(attempt, CompletedAttemptMetric)
623-
assert attempt.end_status.name == "PERMISSION_DENIED"
623+
assert attempt.end_status.name in ["PERMISSION_DENIED", "DEADLINE_EXCEEDED"]
624624
assert (
625625
attempt.gfe_latency_ns >= 0
626626
and attempt.gfe_latency_ns < operation.duration_ns
@@ -1266,7 +1266,7 @@ async def test_bulk_mutate_rows_failure_unauthorized_with_retries(
12661266
)
12671267
# validate attempts
12681268
for attempt in handler.completed_attempts:
1269-
assert attempt.end_status.name == "OK"
1269+
assert attempt.end_status.name in ["OK", "DEADLINE_EXCEEDED"]
12701270
assert (
12711271
attempt.gfe_latency_ns >= 0
12721272
and attempt.gfe_latency_ns < operation.duration_ns
@@ -1658,7 +1658,7 @@ async def test_mutate_row_failure_unauthorized_with_retries(
16581658
)
16591659
# validate attempts
16601660
for attempt in handler.completed_attempts:
1661-
assert attempt.end_status.name == "PERMISSION_DENIED"
1661+
assert attempt.end_status.name in ["PERMISSION_DENIED", "DEADLINE_EXCEEDED"]
16621662
assert (
16631663
attempt.gfe_latency_ns >= 0
16641664
and attempt.gfe_latency_ns < operation.duration_ns

tests/system/data/test_metrics_autogen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def test_read_rows_stream_failure_unauthorized_with_retries(
510510
)
511511
for attempt in handler.completed_attempts:
512512
assert isinstance(attempt, CompletedAttemptMetric)
513-
assert attempt.end_status.name == "PERMISSION_DENIED"
513+
assert attempt.end_status.name in ["PERMISSION_DENIED", "DEADLINE_EXCEEDED"]
514514
assert (
515515
attempt.gfe_latency_ns >= 0
516516
and attempt.gfe_latency_ns < operation.duration_ns
@@ -1053,7 +1053,7 @@ def test_bulk_mutate_rows_failure_unauthorized_with_retries(
10531053
== cluster_config[operation.cluster_id].location.split("/")[-1]
10541054
)
10551055
for attempt in handler.completed_attempts:
1056-
assert attempt.end_status.name == "OK"
1056+
assert attempt.end_status.name in ["OK", "DEADLINE_EXCEEDED"]
10571057
assert (
10581058
attempt.gfe_latency_ns >= 0
10591059
and attempt.gfe_latency_ns < operation.duration_ns
@@ -1376,7 +1376,7 @@ def test_mutate_row_failure_unauthorized_with_retries(
13761376
== cluster_config[operation.cluster_id].location.split("/")[-1]
13771377
)
13781378
for attempt in handler.completed_attempts:
1379-
assert attempt.end_status.name == "PERMISSION_DENIED"
1379+
assert attempt.end_status.name in ["PERMISSION_DENIED", "DEADLINE_EXCEEDED"]
13801380
assert (
13811381
attempt.gfe_latency_ns >= 0
13821382
and attempt.gfe_latency_ns < operation.duration_ns

tests/unit/data/_async/test_read_rows_acceptance.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from google.cloud.bigtable.data.exceptions import InvalidChunk
2626
from google.cloud.bigtable.data.row import Row
27+
from google.cloud.bigtable.data._metrics import ActiveOperationMetric
2728

2829
from ...v2_client.test_row_merger import ReadRowsTest, TestFile
2930

@@ -39,8 +40,12 @@
3940
class TestReadRowsAcceptanceAsync:
4041
@staticmethod
4142
@CrossSync.convert
42-
def _get_operation_class():
43-
return CrossSync._ReadRowsOperation
43+
def _make_operation():
44+
metric = ActiveOperationMetric("READ_ROWS")
45+
op = CrossSync._ReadRowsOperation(mock.Mock(), mock.Mock(), 5, 5, metric)
46+
op._remaining_count = None
47+
return op
48+
4449

4550
@staticmethod
4651
@CrossSync.convert
@@ -83,13 +88,10 @@ async def _process_chunks(self, *chunks):
8388
async def _row_stream():
8489
yield ReadRowsResponse(chunks=chunks)
8590

86-
instance = mock.Mock()
87-
instance._remaining_count = None
88-
instance._last_yielded_row_key = None
89-
chunker = self._get_operation_class().chunk_stream(
90-
instance, self._coro_wrapper(_row_stream())
91+
chunker = self._make_operation().chunk_stream(
92+
self._coro_wrapper(_row_stream())
9193
)
92-
merger = self._get_operation_class().merge_rows(chunker)
94+
merger = self._make_operation().merge_rows(chunker)
9395
results = []
9496
async for row in merger:
9597
results.append(row)
@@ -106,13 +108,10 @@ async def _scenerio_stream():
106108

107109
try:
108110
results = []
109-
instance = mock.Mock()
110-
instance._last_yielded_row_key = None
111-
instance._remaining_count = None
112-
chunker = self._get_operation_class().chunk_stream(
113-
instance, self._coro_wrapper(_scenerio_stream())
111+
chunker = self._make_operation().chunk_stream(
112+
self._coro_wrapper(_scenerio_stream())
114113
)
115-
merger = self._get_operation_class().merge_rows(chunker)
114+
merger = self._make_operation().merge_rows(chunker)
116115
async for row in merger:
117116
for cell in row:
118117
cell_result = ReadRowsTest.Result(
@@ -199,13 +198,12 @@ async def test_out_of_order_rows(self):
199198
async def _row_stream():
200199
yield ReadRowsResponse(last_scanned_row_key=b"a")
201200

202-
instance = mock.Mock()
203-
instance._remaining_count = None
204-
instance._last_yielded_row_key = b"b"
205-
chunker = self._get_operation_class().chunk_stream(
206-
instance, self._coro_wrapper(_row_stream())
201+
op = self._make_operation()
202+
op._last_yielded_row_key = b"b"
203+
chunker = op.chunk_stream(
204+
self._coro_wrapper(_row_stream())
207205
)
208-
merger = self._get_operation_class().merge_rows(chunker)
206+
merger = self._make_operation().merge_rows(chunker)
209207
with pytest.raises(InvalidChunk):
210208
async for _ in merger:
211209
pass

tests/unit/data/_sync_autogen/test_read_rows_acceptance.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@
2323
from google.cloud.bigtable_v2 import ReadRowsResponse
2424
from google.cloud.bigtable.data.exceptions import InvalidChunk
2525
from google.cloud.bigtable.data.row import Row
26+
from google.cloud.bigtable.data._metrics import ActiveOperationMetric
2627
from ...v2_client.test_row_merger import ReadRowsTest, TestFile
2728
from google.cloud.bigtable.data._cross_sync import CrossSync
2829

2930

3031
class TestReadRowsAcceptance:
3132
@staticmethod
32-
def _get_operation_class():
33-
return CrossSync._Sync_Impl._ReadRowsOperation
33+
def _make_operation():
34+
metric = ActiveOperationMetric("READ_ROWS")
35+
op = CrossSync._Sync_Impl._ReadRowsOperation(
36+
mock.Mock(), mock.Mock(), 5, 5, metric
37+
)
38+
op._remaining_count = None
39+
return op
3440

3541
@staticmethod
3642
def _get_client_class():
@@ -68,13 +74,8 @@ def _process_chunks(self, *chunks):
6874
def _row_stream():
6975
yield ReadRowsResponse(chunks=chunks)
7076

71-
instance = mock.Mock()
72-
instance._remaining_count = None
73-
instance._last_yielded_row_key = None
74-
chunker = self._get_operation_class().chunk_stream(
75-
instance, self._coro_wrapper(_row_stream())
76-
)
77-
merger = self._get_operation_class().merge_rows(chunker)
77+
chunker = self._make_operation().chunk_stream(self._coro_wrapper(_row_stream()))
78+
merger = self._make_operation().merge_rows(chunker)
7879
results = []
7980
for row in merger:
8081
results.append(row)
@@ -90,13 +91,10 @@ def _scenerio_stream():
9091

9192
try:
9293
results = []
93-
instance = mock.Mock()
94-
instance._last_yielded_row_key = None
95-
instance._remaining_count = None
96-
chunker = self._get_operation_class().chunk_stream(
97-
instance, self._coro_wrapper(_scenerio_stream())
94+
chunker = self._make_operation().chunk_stream(
95+
self._coro_wrapper(_scenerio_stream())
9896
)
99-
merger = self._get_operation_class().merge_rows(chunker)
97+
merger = self._make_operation().merge_rows(chunker)
10098
for row in merger:
10199
for cell in row:
102100
cell_result = ReadRowsTest.Result(
@@ -179,13 +177,10 @@ def test_out_of_order_rows(self):
179177
def _row_stream():
180178
yield ReadRowsResponse(last_scanned_row_key=b"a")
181179

182-
instance = mock.Mock()
183-
instance._remaining_count = None
184-
instance._last_yielded_row_key = b"b"
185-
chunker = self._get_operation_class().chunk_stream(
186-
instance, self._coro_wrapper(_row_stream())
187-
)
188-
merger = self._get_operation_class().merge_rows(chunker)
180+
op = self._make_operation()
181+
op._last_yielded_row_key = b"b"
182+
chunker = op.chunk_stream(self._coro_wrapper(_row_stream()))
183+
merger = self._make_operation().merge_rows(chunker)
189184
with pytest.raises(InvalidChunk):
190185
for _ in merger:
191186
pass

0 commit comments

Comments
 (0)