port dotnet/corefx#17444 to WebSockets (#162)

This commit is contained in:
Andrew Stanton-Nurse 2017-04-13 09:55:45 -07:00 committed by GitHub
parent 9c2b7b7842
commit e25a2eced8
8 changed files with 72 additions and 57 deletions

View File

@ -5,6 +5,7 @@ env:
global: global:
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
- DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_CLI_TELEMETRY_OPTOUT: 1
- AUTOBAHN_SUITES_LOG: 1
mono: none mono: none
python: python:
- "2.7" - "2.7"

View File

@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26228.4 VisualStudioVersion = 15.0.26411.1
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2C7947A5-9FBD-4267-97C1-2D726D7B3BAF}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2C7947A5-9FBD-4267-97C1-2D726D7B3BAF}"
EndProject EndProject
@ -25,6 +25,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EchoApp", "samples\EchoApp\
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutobahnTestApp", "test\AutobahnTestApp\AutobahnTestApp.csproj", "{150DF5A8-87C6-42F7-8886-CE07BFD02FD2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutobahnTestApp", "test\AutobahnTestApp\AutobahnTestApp.csproj", "{150DF5A8-87C6-42F7-8886-CE07BFD02FD2}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{92CE12E6-E127-433B-96D3-164C0113EA17}"
ProjectSection(SolutionItems) = preProject
build\common.props = build\common.props
build\dependencies.props = build\dependencies.props
build\Key.snk = build\Key.snk
build\repo.props = build\repo.props
build\repo.targets = build\repo.targets
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU

View File

@ -1,5 +1,7 @@
init: init:
- git config --global core.autocrlf true - git config --global core.autocrlf true
environment:
AUTOBAHN_SUITES_LOG: 1
branches: branches:
only: only:
- master - master

View File

@ -1,7 +1,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion> <AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
<AspNetCoreLabsVersion>0.3.0-*</AspNetCoreLabsVersion> <AspNetCoreIntegrationTestingVersion>0.4.0-*</AspNetCoreIntegrationTestingVersion>
<AspNetCoreModuleVersion>1.0.0-*</AspNetCoreModuleVersion> <AspNetCoreModuleVersion>1.0.0-*</AspNetCoreModuleVersion>
<CoreFxVersion>4.3.0</CoreFxVersion> <CoreFxVersion>4.3.0</CoreFxVersion>
<InternalAspNetCoreSdkVersion>2.0.0-*</InternalAspNetCoreSdkVersion> <InternalAspNetCoreSdkVersion>2.0.0-*</InternalAspNetCoreSdkVersion>

View File

@ -732,9 +732,11 @@ namespace System.Net.WebSockets
} }
catch (Exception exc) catch (Exception exc)
{ {
throw _state == WebSocketState.Aborted ? if (_state == WebSocketState.Aborted)
new WebSocketException(WebSocketError.InvalidState, SR.Format(SR.net_WebSockets_InvalidState_ClosedOrAborted, "System.Net.WebSockets.InternalClientWebSocket", "Aborted"), exc) : {
new WebSocketException(WebSocketError.ConnectionClosedPrematurely, exc); throw new OperationCanceledException(nameof(WebSocketState.Aborted), exc);
}
throw new WebSocketException(WebSocketError.ConnectionClosedPrematurely, exc);
} }
finally finally
{ {

View File

@ -7,6 +7,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Xunit; using Xunit;
@ -106,8 +107,8 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
ServerConfigTemplateContent = (server == ServerType.IISExpress) ? File.ReadAllText(configPath) : null, ServerConfigTemplateContent = (server == ServerType.IISExpress) ? File.ReadAllText(configPath) : null,
}; };
var deployer = ApplicationDeployerFactory.Create(parameters, logger); var deployer = ApplicationDeployerFactory.Create(parameters, _loggerFactory);
var result = deployer.Deploy(); var result = await deployer.DeployAsync();
_deployers.Add(deployer); _deployers.Add(deployer);
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();

View File

@ -1,77 +1,77 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn; using Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.PlatformAbstractions;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.WebSockets.ConformanceTest namespace Microsoft.AspNetCore.WebSockets.ConformanceTest
{ {
public class AutobahnTests public class AutobahnTests : LoggedTest
{ {
public AutobahnTests(ITestOutputHelper output) : base(output)
{
}
// Skip if wstest is not installed for now, see https://github.com/aspnet/WebSockets/issues/95 // Skip if wstest is not installed for now, see https://github.com/aspnet/WebSockets/issues/95
// We will enable Wstest on every build once we've gotten the necessary infrastructure sorted out :). // We will enable Wstest on every build once we've gotten the necessary infrastructure sorted out :).
[ConditionalFact] [ConditionalFact]
[SkipIfWsTestNotPresent] [SkipIfWsTestNotPresent]
public async Task AutobahnTestSuite() public async Task AutobahnTestSuite()
{ {
var reportDir = Environment.GetEnvironmentVariable("AUTOBAHN_SUITES_REPORT_DIR"); using (StartLog(out var loggerFactory))
var outDir = !string.IsNullOrEmpty(reportDir) ?
reportDir :
Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "autobahnreports");
if (Directory.Exists(outDir))
{ {
Directory.Delete(outDir, recursive: true); var reportDir = Environment.GetEnvironmentVariable("AUTOBAHN_SUITES_REPORT_DIR");
} var outDir = !string.IsNullOrEmpty(reportDir) ?
reportDir :
Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "autobahnreports");
outDir = outDir.Replace("\\", "\\\\"); if (Directory.Exists(outDir))
// 9.* is Limits/Performance which is VERY SLOW; 12.*/13.* are compression which we don't implement
var spec = new AutobahnSpec(outDir)
.IncludeCase("*")
.ExcludeCase("9.*", "12.*", "13.*");
var loggerFactory = new LoggerFactory(); // No logging by default! It's very loud...
if (string.Equals(Environment.GetEnvironmentVariable("AUTOBAHN_SUITES_LOG"), "1", StringComparison.Ordinal))
{
loggerFactory.AddConsole();
}
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromMinutes(5)); // These tests generally complete in just over 1 minute.
AutobahnResult result;
using (var tester = new AutobahnTester(loggerFactory, spec))
{
await tester.DeployTestAndAddToSpec(ServerType.Kestrel, ssl: false, environment: "ManagedSockets", cancellationToken: cts.Token);
// Windows-only WebListener tests, and Kestrel SSL tests (due to: https://github.com/aspnet/WebSockets/issues/102)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
await tester.DeployTestAndAddToSpec(ServerType.Kestrel, ssl: true, environment: "ManagedSockets", cancellationToken: cts.Token); Directory.Delete(outDir, recursive: true);
if (IsWindows8OrHigher())
{
// WebListener occasionally gives a non-strict response on 3.2. IIS Express seems to have the same behavior. Wonder if it's related to HttpSys?
// For now, just allow the non-strict response, it's not a failure.
await tester.DeployTestAndAddToSpec(ServerType.WebListener, ssl: false, environment: "ManagedSockets", cancellationToken: cts.Token);
}
} }
result = await tester.Run(cts.Token); outDir = outDir.Replace("\\", "\\\\");
tester.Verify(result);
}
// If it hasn't been cancelled yet, cancel the token just to be sure // 9.* is Limits/Performance which is VERY SLOW; 12.*/13.* are compression which we don't implement
cts.Cancel(); var spec = new AutobahnSpec(outDir)
.IncludeCase("*")
.ExcludeCase("9.*", "12.*", "13.*");
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromMinutes(5)); // These tests generally complete in just over 1 minute.
AutobahnResult result;
using (var tester = new AutobahnTester(loggerFactory, spec))
{
await tester.DeployTestAndAddToSpec(ServerType.Kestrel, ssl: false, environment: "ManagedSockets", cancellationToken: cts.Token);
// Windows-only WebListener tests, and Kestrel SSL tests (due to: https://github.com/aspnet/WebSockets/issues/102)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
await tester.DeployTestAndAddToSpec(ServerType.Kestrel, ssl: true, environment: "ManagedSockets", cancellationToken: cts.Token);
if (IsWindows8OrHigher())
{
// WebListener occasionally gives a non-strict response on 3.2. IIS Express seems to have the same behavior. Wonder if it's related to HttpSys?
// For now, just allow the non-strict response, it's not a failure.
await tester.DeployTestAndAddToSpec(ServerType.WebListener, ssl: false, environment: "ManagedSockets", cancellationToken: cts.Token);
}
}
result = await tester.Run(cts.Token);
tester.Verify(result);
}
// If it hasn't been cancelled yet, cancel the token just to be sure
cts.Cancel();
}
} }
private bool IsWindows8OrHigher() private bool IsWindows8OrHigher()

View File

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting" Version="$(AspNetCoreLabsVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting" Version="$(AspNetCoreIntegrationTestingVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />