Skip to content
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

Fix digital twins query pagination test #16087

Merged
merged 3 commits into from
Oct 19, 2020

Conversation

timtay-microsoft
Copy link
Member

This test frequently failed claiming that only one page of results was returned from a query. In order to fix this, the test will now create more than just the minimum amount of queryable twins, and it will wait until at least pageSize + 1 twins can be queried before testing that we can control the page size

This test frequently failed claiming that only one page of results was returned from a query. In order to fix this, the test will now create more than just the minimum amount of queryable twins, and it will wait until at least pageSize + 1 twins can be queried before testing that we can control the page size
@@ -97,13 +99,35 @@ public async Task Query_PaginationWorks()
// act
var options = new QueryOptions();
options.MaxItemsPerPage = pageSize;
AsyncPageable<string> asyncPageableResponse = client.QueryAsync(queryString, options);

var queryWaitTimeoutStopwatch = new Stopwatch();
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi you can do Stopwatch.StartNew() to make this and only take 1 statement instead of 2. :)

queryWaitTimeoutStopwatch.Start();
while (!queryHasExpectedCount)
{
if (queryWaitTimeoutStopwatch.ElapsedMilliseconds >= QueryWaitTimeoutMillis)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use a timed cancellation token source instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, so we keep running the query until it finally returns all the items we expect? There must be a delay in items being created and then showing up in a query. Is that right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I'm a Java developer, haha...

Copy link
Member Author

Choose a reason for hiding this comment

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

I like that idea better for .NET code, though, sure

Copy link
Member Author

@timtay-microsoft timtay-microsoft Oct 19, 2020

Choose a reason for hiding this comment

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

Oh, so we keep running the query until it finally returns all the items we expect? There must be a delay in items being created and then showing up in a query. Is that right?

That's my hunch, yes. I've seen this same issue in our query tests in IoT Hub, and this fix stabilized the tests


AsyncPageable<string> asyncPageableResponse = client.QueryAsync(queryString);
int count = 0;
await foreach (string queriedTwin in asyncPageableResponse)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you enumerate pages instead of items, do the pages tell you how many items are in it?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does. I can iterate over the pages here and just do count+=page.Values.Count; instead

throw new AssertionException($"Timed out waiting for at least {pageSize + 1} twins to be queryable");
}

AsyncPageable<string> asyncPageableResponse = client.QueryAsync(queryString);
Copy link
Contributor

Choose a reason for hiding this comment

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

do you want to pass the cancellation token into this or the AsPages methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, just in case

@timtay-microsoft timtay-microsoft merged commit bbf79d1 into master Oct 19, 2020
@timtay-microsoft timtay-microsoft deleted the feature/adt/timtay/paginationTestFix branch October 19, 2020 21:06
annelo-msft pushed a commit to annelo-msft/azure-sdk-for-net that referenced this pull request Feb 17, 2021
This test frequently failed claiming that only one page of results was returned from a query. In order to fix this, the test will now create more than just the minimum amount of queryable twins, and it will wait until at least pageSize + 1 twins can be queried before testing that we can control the page size
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.

2 participants