Fix flaky AbortedStream test in Kestrel (#8010)

This commit is contained in:
Justin Kotalik 2019-02-27 20:55:10 -08:00 committed by GitHub
parent 896c027010
commit 555e460c15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -25,6 +25,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using Moq; using Moq;
using Xunit; using Xunit;
@ -177,7 +178,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
_mockConnectionContext.Setup(c => c.Abort(It.IsAny<ConnectionAbortedException>())).Callback<ConnectionAbortedException>(ex => _mockConnectionContext.Setup(c => c.Abort(It.IsAny<ConnectionAbortedException>())).Callback<ConnectionAbortedException>(ex =>
{ {
// Emulate transport abort so the _connectionTask completes. // Emulate transport abort so the _connectionTask completes.
Task.Run(() => _pair.Application.Output.Complete(ex)); Task.Run(() =>
{
TestApplicationErrorLogger.LogInformation(0, ex, "ConnectionContext.Abort() was called. Completing _pair.Application.Output.");
_pair.Application.Output.Complete(ex);
});
}); });
_noopApplication = context => Task.CompletedTask; _noopApplication = context => Task.CompletedTask;

View File

@ -198,6 +198,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
[InlineData(Http2FrameType.CONTINUATION)] [InlineData(Http2FrameType.CONTINUATION)]
public async Task AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterCooldownExpires(Http2FrameType finalFrameType) public async Task AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterCooldownExpires(Http2FrameType finalFrameType)
{ {
// Remove callback that completes _pair.Application.Output on abort.
_mockConnectionContext.Reset();
var mockSystemClock = _serviceContext.MockSystemClock; var mockSystemClock = _serviceContext.MockSystemClock;
var headers = new[] var headers = new[]