Fix flaky ClientStreaming_ResponseCompletesWithoutResponseBody… (#20338)

This commit is contained in:
James Newton-King 2020-04-02 09:02:09 +13:00 committed by GitHub
parent 7d450bba80
commit f1145fb6d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 19 deletions

View File

@ -115,10 +115,25 @@ namespace Microsoft.AspNetCore.TestHost
// This could throw an error if there was a pending server read. Needs to
// happen before completing the response so the response returns the error.
var requestBodyInProgress = RequestBodyReadInProgress();
if (requestBodyInProgress)
{
// If request is still in progress then abort it.
CancelRequestBody();
}
// Matches Kestrel server: response is completed before request is drained
await CompleteResponseAsync();
await CompleteRequestAsync(requestBodyInProgress);
if (!requestBodyInProgress)
{
// Writer was already completed in send request callback.
await _requestPipe.Reader.CompleteAsync();
// Don't wait for request to drain. It could block indefinitely. In a real server
// we would wait for a timeout and then kill the socket.
// Potential future improvement: add logging that the request timed out
}
_application.DisposeContext(_testContext, exception: null);
}
catch (Exception ex)
@ -165,24 +180,6 @@ namespace Microsoft.AspNetCore.TestHost
CancelRequestBody();
}
private async Task CompleteRequestAsync(bool requestBodyInProgress)
{
if (requestBodyInProgress)
{
// If request is still in progress then abort it.
CancelRequestBody();
}
else
{
// Writer was already completed in send request callback.
await _requestPipe.Reader.CompleteAsync();
}
// Don't wait for request to drain. It could block indefinitely. In a real server
// we would wait for a timeout and then kill the socket.
// Potential future improvement: add logging that the request timed out
}
private bool RequestBodyReadInProgress()
{
try