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

Enable GetAsync_CancelDuringResponseBodyReceived_Buffered_TaskCanceledQuickly #32032

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ await ValidateClientCancellationAsync(async () =>
}

[Theory]
[ActiveIssue("https://github.com/dotnet/corefx/issues/28805")]
[MemberData(nameof(TwoBoolsAndCancellationMode))]
public async Task GetAsync_CancelDuringResponseBodyReceived_Buffered_TaskCanceledQuickly(bool chunkedTransfer, bool connectionClose, CancellationMode mode)
{
Expand All @@ -140,6 +139,7 @@ public async Task GetAsync_CancelDuringResponseBodyReceived_Buffered_TaskCancele
{
client.Timeout = Timeout.InfiniteTimeSpan;
var cts = new CancellationTokenSource();
int timeout = 120_000;

await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
{
Expand Down Expand Up @@ -167,18 +167,18 @@ await ValidateClientCancellationAsync(async () =>
req.Headers.ConnectionClose = connectionClose;

Task<HttpResponseMessage> getResponse = client.SendAsync(req, HttpCompletionOption.ResponseContentRead, cts.Token);
await responseHeadersSent.Task;
await Task.Delay(1); // make it more likely that client will have started processing response body
await responseHeadersSent.Task.TimeoutAfter(timeout);
//await Task.Delay(1).TimeoutAfter(timeout); // make it more likely that client will have started processing response body
Cancel(mode, client, cts);
await getResponse;
});
await getResponse.TimeoutAfter(timeout);
}).TimeoutAfter(timeout);

try
{
clientFinished.SetResult(true);
await serverTask;
} catch { }
});
}, 500_000);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public override GenericLoopbackServer CreateServer(GenericLoopbackOptions option

public override Task CreateServerAsync(Func<GenericLoopbackServer, Uri, Task> funcAsync, int millisecondsTimeout = 60_000, GenericLoopbackOptions options = null)
{
return LoopbackServer.CreateServerAsync((server, uri) => funcAsync(server, uri), options: CreateOptions(options));
return LoopbackServer.CreateServerAsync((server, uri) => funcAsync(server, uri).TimeoutAfter(millisecondsTimeout), options: CreateOptions(options));
}

private static LoopbackServer.Options CreateOptions(GenericLoopbackOptions options)
Expand Down