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

Change SendAsync_SlowServerRespondsAfterDefaultReceiveTimeout_ThrowsHttpRequestException server to Loopback #93025

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public async Task GetAsync_RedirectResponseHasCookie_CookieSentToFinalUri(

[OuterLoop]
[Fact]
[OuterLoop]
liveans marked this conversation as resolved.
Show resolved Hide resolved
public async Task SendAsync_SlowServerAndCancel_ThrowsTaskCanceledException()
{
var handler = new WinHttpHandler();
Expand All @@ -97,19 +96,36 @@ public async Task SendAsync_SlowServerAndCancel_ThrowsTaskCanceledException()
}
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/20675")]
[OuterLoop]
[Fact]
[OuterLoop]
public void SendAsync_SlowServerRespondsAfterDefaultReceiveTimeout_ThrowsHttpRequestException()
public async void SendAsync_SlowServerRespondsAfterDefaultReceiveTimeout_ThrowsHttpRequestException()
{
var handler = new WinHttpHandler();
using (var client = new HttpClient(handler))
{
Task<HttpResponseMessage> t = client.GetAsync(SlowServer);
var triggerResponseWrite = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
liveans marked this conversation as resolved.
Show resolved Hide resolved
var triggerRequestWait = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);

AggregateException ag = Assert.Throws<AggregateException>(() => t.Wait());
Assert.IsType<HttpRequestException>(ag.InnerException);
await LoopbackServer.CreateServerAsync(async (server, url) =>
{
Task serverTask = server.AcceptConnectionAsync(async connection =>
{
await connection.SendResponseAsync($"HTTP/1.1 200 OK\r\nDate: {DateTimeOffset.UtcNow:R}\r\nContent-Length: 16000\r\n\r\n");
Copy link
Member

Choose a reason for hiding this comment

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

You're postponing the timeout to the response body portion of HTTP exchange, right? If so, HttpClient.GetAsync will succeed as it by default reads only response headers and doesn't wait for the body.

Copy link
Member

Choose a reason for hiding this comment

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

HttpClient.GetAsync will succeed as it by default reads only response headers and doesn't wait for the body

HttpClient.GetAsync is passing HttpCompletionOption.ResponseContentRead to HttpClient.SendAsync which should enforce reading and buffering the response body. Or am I missing something?


triggerRequestWait.SetResult(true);
await triggerResponseWrite.Task;
});

AggregateException ag = await Assert.ThrowsAsync<AggregateException>(async () =>
{
Task<HttpResponseMessage> t = client.GetAsync(url);
await triggerRequestWait.Task;
t.Wait();
liveans marked this conversation as resolved.
Show resolved Hide resolved
});
Assert.IsType<HttpRequestException>(ag.InnerException);

triggerResponseWrite.SetResult(true);
});
}
}

Expand Down
Loading