Skip to content

Commit

Permalink
test: add tests for large offsets in datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
crwilcox committed Mar 31, 2020
1 parent 96fd5b8 commit 010834d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/system/test_system.py
Expand Up @@ -405,6 +405,18 @@ def test_query_offset_timestamp_keys(self):
offset_w_limit = list(query.fetch(offset=offset, limit=max_offset))
self.assertEqual(offset_w_limit, all_w_limit[offset:])

def test_query_large_offset_timestamp_keys(self):
# See issue #4675
max_all = 10000
offset = 21
max_offset = max_all - offset
query = self.CLIENT.query(kind="timestamp_key")
all_w_limit = list(query.fetch(limit=max_all))
self.assertEqual(len(all_w_limit), max_all)

offset_w_limit = list(query.fetch(offset=offset, limit=max_offset))
self.assertEqual(offset_w_limit, all_w_limit[offset:])

def test_query_paginate_with_offset(self):
page_query = self._base_query()
page_query.order = "appearances"
Expand All @@ -429,6 +441,24 @@ def test_query_paginate_with_offset(self):
self.assertEqual(entities[1]["name"], "Jon Snow")
self.assertEqual(entities[2]["name"], "Arya")

def test_query_paginate_with_large_offset(self):
page_query = self._base_query()
page_query.order = "appearances"
offset = 21
limit = 3
iterator = page_query.fetch(limit=limit, offset=offset)

# Fetch characters.
page = six.next(iterator.pages)
entities = list(page)
cursor = iterator.next_page_token
self.assertEqual(len(entities), 0)

# Fetch next set of characters.
new_iterator = page_query.fetch(limit=limit, offset=0, start_cursor=cursor)
entities = list(new_iterator)
self.assertEqual(len(entities), 0)

def test_query_paginate_with_start_cursor(self):
page_query = self._base_query()
page_query.order = "appearances"
Expand Down

0 comments on commit 010834d

Please sign in to comment.