Skip to content

Commit

Permalink
tests: complete coverage of 'PartialRowsData' (#338)
Browse files Browse the repository at this point in the history
Add a test for cancellation during iteration of rows.

Toward #335
  • Loading branch information
tseaver authored Jun 25, 2021
1 parent a9978d4 commit d93995f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tests/unit/test_row_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def test_multiple_chunks(self):
client._table_data_client = data_api
request = object()

yrd = self._make_one(client._table_data_client.read_rows, request)
yrd = self._make_one(data_api.read_rows, request)

yrd.response_iterator = iterator
rows = [row for row in yrd]
Expand All @@ -511,6 +511,42 @@ def test_cancel(self):
self.assertEqual(response_iterator.cancel_calls, 1)
self.assertEqual(list(yield_rows_data), [])

def test_cancel_between_chunks(self):
from google.cloud.bigtable_v2.services.bigtable import BigtableClient

chunk1 = _ReadRowsResponseCellChunkPB(
row_key=self.ROW_KEY,
family_name=self.FAMILY_NAME,
qualifier=self.QUALIFIER,
timestamp_micros=self.TIMESTAMP_MICROS,
value=self.VALUE,
commit_row=True,
)
chunk2 = _ReadRowsResponseCellChunkPB(
qualifier=self.QUALIFIER + b"1",
timestamp_micros=self.TIMESTAMP_MICROS,
value=self.VALUE,
commit_row=True,
)
chunks = [chunk1, chunk2]
response = _ReadRowsResponseV2(chunks)
response_iterator = _MockCancellableIterator(response)

client = _Client()
data_api = mock.create_autospec(BigtableClient)
client._table_data_client = data_api
request = object()
yrd = self._make_one(data_api.read_rows, request)
yrd.response_iterator = response_iterator

rows = []
for row in yrd:
yrd.cancel()
rows.append(row)

self.assertEqual(response_iterator.cancel_calls, 1)
self.assertEqual(list(yrd), [])

# 'consume_next' tested via 'TestPartialRowsData_JSON_acceptance_tests'

def test__copy_from_previous_unset(self):
Expand Down

0 comments on commit d93995f

Please sign in to comment.