question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlurlCall.Succeeded should null-check response, not request

See original GitHub issue

After upgrading Flurl 2.x to 3.0 some tests fail.

I identified the issue, it seems to be related to the SimulateTimeout. If I call SimulateTimeout and not add a RespondWith after, all next calls will throw FlurlHttpTimeoutException, that was not the case with Flurl 2.x.

Some tests (XUnit + Shouldly) to illustrate the issue.

[Fact]
public async Task TestOk()
{
    FlurlClient flurlClient = new FlurlClient("http://fakeurl.io/api");

    await Should.NotThrowAsync(async () => await flurlClient.Request().GetAsync());
}

[Fact]
public async Task TestTimeoutOk()
{
    HttpTest.SimulateTimeout();

    FlurlClient flurlClient = new FlurlClient("http://fakeurl.io/api");

    await Should.ThrowAsync<FlurlHttpTimeoutException>(async () => await flurlClient.Request().GetAsync());

    HttpTest.RespondWith();

    await Should.NotThrowAsync(async () => await flurlClient.Request().GetAsync());
}

[Fact]
public async Task TestTimeoutKo()
{
    HttpTest.SimulateTimeout();

    FlurlClient flurlClient = new FlurlClient("http://fakeurl.io/api");

    await Should.ThrowAsync<FlurlHttpTimeoutException>(async () => await flurlClient.Request().GetAsync());

    await Should.NotThrowAsync(async () => await flurlClient.Request().GetAsync());
}

I tried to workaround the issue by calling RespondWith just after SimulateTimeout, this fixed most of the tests.

But I encountered another issue.

System.NullReferenceException Object reference not set to an instance of an object. at Flurl.Http.FlurlCall.get_Succeeded()

From the code : https://github.com/tmenier/Flurl/blob/ed1e7bdf41ca7ebc5928f24f94c71cdc6a351a62/src/Flurl.Http/FlurlCall.cs#L84

I think there is a typo, HttpRequestMessage need to be HttpResponseMessage

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tmeniercommented, Dec 14, 2020

Fixed & released in 3.0.1. Your work-around is no longer needed.

1reaction
tmeniercommented, Nov 28, 2020

Thanks, but you did still catch a small bug at the end there so I’ll keep this open until that’s fixed/released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FlurlCall.Succeeded should null-check response, not request
After upgrading Flurl 2.x to 3.0 some tests fail. I identified the issue, it seems to be related to the SimulateTimeout. If I...
Read more >
NullReferenceException when make a PUT request using ...
1 Answer. I suspect that the actual HTTP call is failing to get a response, and Flurl is trying to read the cookies...
Read more >
Error Handling
Http throws on any non-2XX HTTP status by default. ... Call.Response , so you can go that route if you need something different,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found