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

HttpTest with Recursive Calls #559

Closed
mkeuschn opened this issue Oct 22, 2020 · 2 comments
Closed

HttpTest with Recursive Calls #559

mkeuschn opened this issue Oct 22, 2020 · 2 comments
Labels

Comments

@mkeuschn
Copy link

I have created a recursive retry logic if the call raises a FlurHttpException.

Implementation:

    public async Task<bool> DoAsync(int retry = 1)
    {
        HttpResponseMessage response;
        try
        {
            response = await "http://www.google.com".GetAsync();
        }
        catch (FlurlHttpException e)
        {
            if (retry <= 3)
            {
                Thread.Sleep(new TimeSpan(0, 0, 1 * retry));
                return await DoAsync(++retry);
            }
            Console.WriteLine(e);
            throw;
        }

        return response.IsSuccessStatusCode;
    }

Test:

    [Fact]
    public async Task DoAsyncTest()
    {
        using var httpTest = new HttpTest();
        httpTest.RespondWith("Internal Server Error", 500);
        var service = new MyService();
        var result = await service.DoAsync();
        result.ShouldBeTrue();
    }

In the first round the 500 response is returned as expected, but in the second round the call responded with 200 OK.
Do I am using this in the right way or is this a bug?

@mkeuschn mkeuschn added the bug label Oct 22, 2020
@tmenier
Copy link
Owner

tmenier commented Oct 22, 2020

Depends on the version of Flurl. :) If you're on 2.x, the behavior is by design. With 3.x that changes. See #482.

@mkeuschn
Copy link
Author

Ok, thank you. I have tried both v2 and v3. I like the v3 behaviour and will stick with this release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants