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

[BUG] AsyncPageable.FromPages doesn't return a pageable object #22705

Closed
cyrildurand opened this issue Jul 17, 2021 · 1 comment · Fixed by #22706
Closed

[BUG] AsyncPageable.FromPages doesn't return a pageable object #22705

cyrildurand opened this issue Jul 17, 2021 · 1 comment · Fixed by #22706
Assignees
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@cyrildurand
Copy link
Contributor

cyrildurand commented Jul 17, 2021

For one of my test I'm trying to mock an AsyncPageable object. I use the FromPages, AsPages and FromValues methods.

I read this article that explain mocking and asyncpageable but multi page is not mentionned.

My code is similar to this :

    var page1 = new List<String>() { "A", "B" };
    var page2 = new List<String>() { "C", "D" };

    var pages = AsyncPageable<String>.FromPages(new[] {
        Page<String>.FromValues(page1, "X", Mock.Of<Response>()),
        Page<String>.FromValues(page2, null, Mock.Of<Response>())
    });

When I'm requesting the first page, without a continuationToken value

    var q = pages.AsPages(continuationToken: null);
    var currentPage = await q.FirstOrDefaultAsync();

currentPage contains 2 elements (A, B) and the continuationToken is set to X.

When I'm requesting for the second page, with a continuationToken of X

    var q = pages.AsPages(continuationToken: "X");
    var currentPage = await q.FirstOrDefaultAsync();

currentPage is still the first page and not the second page.

Expected behavior

When we query for another page with a valid continuationToken we obtain the corresponding page and not the first page.

Actual behavior (include Exception or Stack Trace)

The issue only happens when I'm using mocking an AsyncPageable with FromPages. When I'm requesting data from CosmosDb everything works normally.

The issue seems to come from Pageable.cs#L127. FromPages returns a StaticPageable and then in the AsPages method The continuationToken is ignored.

        public override IEnumerable<Page<T>> AsPages(string? continuationToken = default, int? pageSizeHint = default)
        {
            return _pages;
        }

To Reproduce

    [Fact]
    public async Task AsyncPageableTest()
    {
        var page1 = new List<String>() { "A", "B" };
        var page2 = new List<String>() { "C", "D" };

        var pages = AsyncPageable<String>.FromPages(new[] {
            Page<String>.FromValues(page1, "X", Mock.Of<Response>()),
            Page<String>.FromValues(page2, null, Mock.Of<Response>())
        });

        // test first page : OK
        var q = pages.AsPages(continuationToken: null);
        var currentPage = await q.FirstOrDefaultAsync();

        Assert.Collection(currentPage.Values,
            o => Assert.Equal("A", o),
            o => Assert.Equal("B", o)
        );
        Assert.Equal("X", currentPage.ContinuationToken);


        // test second page : KO
        q = pages.AsPages(continuationToken: "X");
        currentPage = await q.FirstOrDefaultAsync();

        Assert.Collection(currentPage.Values,
            o => Assert.Equal("C", o),
            o => Assert.Equal("D", o)
        );
        Assert.Null(currentPage.ContinuationToken);
    }

Environment:

  • Name and version of the Library package used: Azure.Core 1.8.1.0
  • Hosting platform or OS and .NET runtime version (dotnet --info output for .NET Core projects):
PS C:\XXX> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.205
 Commit:    64a0cf25eb

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.205\

Host (useful for support):
  Version: 5.0.8
  Commit:  35964c9215

.NET SDKs installed:
  3.1.411 [C:\Program Files\dotnet\sdk]
  5.0.203 [C:\Program Files\dotnet\sdk]
  5.0.205 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]  
  Microsoft.WindowsDesktop.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]  
  Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]   
  Microsoft.WindowsDesktop.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]   

  • IDE and version : Visual Studio 16.9.6
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jul 17, 2021
@jsquire jsquire added Azure.Core Client This issue points to a problem in the data-plane of the library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Jul 19, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jul 19, 2021
@jsquire
Copy link
Member

jsquire commented Jul 19, 2021

Thank you for your feedback. Tagging and routing to the team member best able to assist.

azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Mar 6, 2023
[Hub Generated] Review request for Microsoft.Security to add version preview/2023-02-01-preview (Azure#22797)

* Adds base for updating Microsoft.Security from version preview/2020-07-01-preview to version 2023-02-01-preview

* Updates readme

* Updates API version in new specs and examples

* Update new API version (Azure#22705)

* Remove versioning (Azure#22745)

* Updade readme (Azure#22871)

* Updade readme

* Trigger new validations

* Remove old swaggers from default tag (Azure#22917)
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants