Skip to content

ResultSet: add tests to cover paging with empty pages #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/unit/test_resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def test_iter_paged(self):
type(response_future).has_more_pages = PropertyMock(side_effect=(True, True, False)) # after init to avoid side effects being consumed by init
self.assertListEqual(list(itr), expected)

def test_iter_paged_with_empty_pages(self):
expected = list(range(10))
response_future = Mock(has_more_pages=True, _continuous_paging_session=None)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it ok to always return has_more_pages==True? Shouldn't it return False for the last page?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because stopIteration will be raised anyway, so in the scope of this test, we do not need to add the complexity of chaging the paging state of the response future to demonstrate and test the fixed behavior

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have a bad day because I don't see how it works.
If has_more_pages is True then the condition in this if will be false and the exception won't be raised, no?
That in turn will lead to next being called again recursively over and over gain, no?

or will the StopIteration be thrown from fetch_next_page?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand it's not obvious sorry.

The StopIteration comes from the mocked response_future.result() iterator over the configured side_effects.

In other words, the tests do iterate over the side_effects every time response_future.result() is called in fetch_next_page(), when all the side_effects (pages) have been depleted, the next call to response_future.result() will raise a StopIteration exception.

Does that make more sense?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. That's what I meant by StopIteration being thrown from fetch_next_page. Thanks.

response_future.result.side_effect = [
ResultSet(Mock(), []),
ResultSet(Mock(), [0, 1, 2, 3, 4]),
ResultSet(Mock(), []),
ResultSet(Mock(), [5, 6, 7, 8, 9]),
]
rs = ResultSet(response_future, [])
itr = iter(rs)
self.assertListEqual(list(itr), expected)

def test_list_non_paged(self):
# list access on RS for backwards-compatibility
expected = list(range(10))
Expand Down