Fix flaky disconnect test (#1533)

This commit is contained in:
Pavel Krymets 2018-10-18 12:37:13 -07:00 committed by GitHub
parent 55d849a0d0
commit 293d165a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions

View File

@ -184,11 +184,11 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
} }
} }
private void AbortIO() private bool AbortIO()
{ {
if (Interlocked.CompareExchange(ref _requestAborted, 1, 0) != 0) if (Interlocked.CompareExchange(ref _requestAborted, 1, 0) != 0)
{ {
return; return false;
} }
_bodyOutput.Dispose(); _bodyOutput.Dispose();
@ -208,6 +208,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
} }
}); });
} }
return true;
} }
public void Abort(Exception reason) public void Abort(Exception reason)
@ -221,8 +223,10 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
internal void ConnectionReset() internal void ConnectionReset()
{ {
AbortIO(); if (AbortIO())
Log.ConnectionDisconnect(_logger, ((IHttpConnectionFeature)this).ConnectionId); {
Log.ConnectionDisconnect(_logger, ((IHttpConnectionFeature)this).ConnectionId);
}
} }
} }
} }

View File

@ -52,7 +52,9 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
{ {
if (_stopped) if (_stopped)
{ {
throw new IOException("IO stopped", NativeMethods.ERROR_OPERATION_ABORTED); // Abort all operation after IO was stopped
ioOperation.Complete(NativeMethods.ERROR_OPERATION_ABORTED, 0);
return;
} }
if (_runningOperation != null) if (_runningOperation != null)

View File

@ -2,13 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
@ -207,8 +205,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
} }
Assert.IsType<OperationCanceledException>(exception); Assert.IsType<OperationCanceledException>(exception);
} }
AssertConnectionDisconnectLog();
} }
[ConditionalFact] [ConditionalFact]
@ -289,7 +285,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
private void AssertConnectionDisconnectLog() private void AssertConnectionDisconnectLog()
{ {
Assert.Contains(TestSink.Writes, w => w.EventId.Name == "ConnectionDisconnect"); Assert.Single(TestSink.Writes, w => w.EventId.Name == "ConnectionDisconnect");
} }
private static async Task SendContentLength1Post(TestConnection connection) private static async Task SendContentLength1Post(TestConnection connection)

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
{ {
[SkipIfHostableWebCoreNotAvailable] [SkipIfHostableWebCoreNotAvailable]
[OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, "https://github.com/aspnet/IISIntegration/issues/866")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, "https://github.com/aspnet/IISIntegration/issues/866")]
public class TestServerTest : LoggedTest public class TestServerTest : StrictTestServerTests
{ {
[ConditionalFact] [ConditionalFact]
public async Task SingleProcessTestServer_HelloWorld() public async Task SingleProcessTestServer_HelloWorld()