From e25a2eced8ff67eb175cdd0e074d48f230636711 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Thu, 13 Apr 2017 09:55:45 -0700 Subject: [PATCH] port dotnet/corefx#17444 to WebSockets (#162) --- .travis.yml | 1 + WebSockets.sln | 11 ++- appveyor.yml | 2 + build/dependencies.props | 4 +- .../System/Net/WebSockets/ManagedWebSocket.cs | 8 +- .../Autobahn/AutobahnTester.cs | 5 +- .../AutobahnTests.cs | 96 +++++++++---------- ...pNetCore.WebSockets.ConformanceTest.csproj | 2 +- 8 files changed, 72 insertions(+), 57 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1513d96c35..ad7de83e50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ env: global: - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_CLI_TELEMETRY_OPTOUT: 1 + - AUTOBAHN_SUITES_LOG: 1 mono: none python: - "2.7" diff --git a/WebSockets.sln b/WebSockets.sln index 30be8b4f80..512fa24505 100644 --- a/WebSockets.sln +++ b/WebSockets.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 +VisualStudioVersion = 15.0.26411.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2C7947A5-9FBD-4267-97C1-2D726D7B3BAF}" EndProject @@ -25,6 +25,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EchoApp", "samples\EchoApp\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutobahnTestApp", "test\AutobahnTestApp\AutobahnTestApp.csproj", "{150DF5A8-87C6-42F7-8886-CE07BFD02FD2}" 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 GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/appveyor.yml b/appveyor.yml index 1041615c68..84253e7820 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,7 @@ init: - git config --global core.autocrlf true +environment: + AUTOBAHN_SUITES_LOG: 1 branches: only: - master diff --git a/build/dependencies.props b/build/dependencies.props index f702c7e7f3..fd031b40af 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,7 +1,7 @@ - + 2.0.0-* - 0.3.0-* + 0.4.0-* 1.0.0-* 4.3.0 2.0.0-* diff --git a/src/Microsoft.AspNetCore.WebSockets/Internal/fx/src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs b/src/Microsoft.AspNetCore.WebSockets/Internal/fx/src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs index 494b6a786d..ea8b828efe 100644 --- a/src/Microsoft.AspNetCore.WebSockets/Internal/fx/src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs +++ b/src/Microsoft.AspNetCore.WebSockets/Internal/fx/src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs @@ -732,9 +732,11 @@ namespace System.Net.WebSockets } catch (Exception exc) { - throw _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); + if (_state == WebSocketState.Aborted) + { + throw new OperationCanceledException(nameof(WebSocketState.Aborted), exc); + } + throw new WebSocketException(WebSocketError.ConnectionClosedPrematurely, exc); } finally { diff --git a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/AutobahnTester.cs b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/AutobahnTester.cs index ccd9241104..5d2e6f44a1 100644 --- a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/AutobahnTester.cs +++ b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/AutobahnTester.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Server.IntegrationTesting.xunit; using Microsoft.Extensions.Logging; using Newtonsoft.Json.Linq; using Xunit; @@ -106,8 +107,8 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn ServerConfigTemplateContent = (server == ServerType.IISExpress) ? File.ReadAllText(configPath) : null, }; - var deployer = ApplicationDeployerFactory.Create(parameters, logger); - var result = deployer.Deploy(); + var deployer = ApplicationDeployerFactory.Create(parameters, _loggerFactory); + var result = await deployer.DeployAsync(); _deployers.Add(deployer); cancellationToken.ThrowIfCancellationRequested(); diff --git a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/AutobahnTests.cs b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/AutobahnTests.cs index c4a2b29601..e37e1b6d20 100644 --- a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/AutobahnTests.cs +++ b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/AutobahnTests.cs @@ -1,77 +1,77 @@ using System; using System.Diagnostics; using System.IO; -using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Server.IntegrationTesting.xunit; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; +using Xunit.Abstractions; 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 // We will enable Wstest on every build once we've gotten the necessary infrastructure sorted out :). [ConditionalFact] [SkipIfWsTestNotPresent] public async Task AutobahnTestSuite() { - var reportDir = Environment.GetEnvironmentVariable("AUTOBAHN_SUITES_REPORT_DIR"); - var outDir = !string.IsNullOrEmpty(reportDir) ? - reportDir : - Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "autobahnreports"); - - if (Directory.Exists(outDir)) + using (StartLog(out var loggerFactory)) { - 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("\\", "\\\\"); - - // 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)) + if (Directory.Exists(outDir)) { - 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); - } + Directory.Delete(outDir, recursive: true); } - result = await tester.Run(cts.Token); - tester.Verify(result); - } + outDir = outDir.Replace("\\", "\\\\"); - // If it hasn't been cancelled yet, cancel the token just to be sure - cts.Cancel(); + // 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 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() diff --git a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Microsoft.AspNetCore.WebSockets.ConformanceTest.csproj b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Microsoft.AspNetCore.WebSockets.ConformanceTest.csproj index e70d57c968..18d5fc8df7 100644 --- a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Microsoft.AspNetCore.WebSockets.ConformanceTest.csproj +++ b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Microsoft.AspNetCore.WebSockets.ConformanceTest.csproj @@ -7,7 +7,7 @@ - +