Skip to content

Commit

Permalink
Change SendAsync_SlowServerRespondsAfterDefaultReceiveTimeout_ThrowsH…
Browse files Browse the repository at this point in the history
…ttpRequestException server to Loopback (#93025)

* Change test server from external server to never responding loopback server

* Review feedback

* Delete date from response

* Delete get content explicitly
  • Loading branch information
liveans authored Oct 7, 2023
1 parent b0a476c commit b21d709
Showing 1 changed file with 25 additions and 7 deletions.
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]
public async Task SendAsync_SlowServerAndCancel_ThrowsTaskCanceledException()
{
var handler = new WinHttpHandler();
Expand All @@ -97,19 +96,38 @@ 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>();
var triggerRequestWait = new TaskCompletionSource<bool>();

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\nContent-Length: 16000\r\n\r\n");
triggerRequestWait.SetResult(true);
await triggerResponseWrite.Task;
});
HttpRequestException ex = await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
Task<HttpResponseMessage> t = client.GetAsync(url);
await triggerRequestWait.Task;
var _ = await t;
});
Assert.IsType<IOException>(ex.InnerException);
Assert.NotNull(ex.InnerException.InnerException);
Assert.Contains("The operation timed out", ex.InnerException.InnerException.Message);
triggerResponseWrite.SetResult(true);
});
}
}

Expand Down

0 comments on commit b21d709

Please sign in to comment.