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

Conversation

ultrabug
Copy link
Collaborator

Related to #102

@ultrabug
Copy link
Collaborator Author

As request, ping @haaawk @fruch

@@ -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.

Copy link

@haaawk haaawk left a comment

Choose a reason for hiding this comment

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

LGTM @fruch @bentsi would you mind having a look please?

@ultrabug
Copy link
Collaborator Author

#need a pypi release plz

Copy link

@fruch fruch left a comment

Choose a reason for hiding this comment

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

LGTM

@fruch fruch merged commit 6ab75d9 into master Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants