diff --git a/.travis.yml b/.travis.yml index c553197516..05069ec25f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,10 @@ env: - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - AUTOBAHN_SUITES_LOG: 1 + - ASPNETCORE_WSTEST_PATH: "$TRAVIS_BUILD_DIR/.virtualenv/bin/wstest" mono: none python: - - "2.7" + - pypy os: - linux - osx @@ -23,9 +24,7 @@ branches: - release - dev - /^(.*\/)?ci-.*$/ -before_install: - - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl python; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi install: - - pip install autobahntestsuite "six>=1.9.0" + - ./build/setup-wstest.sh script: - ./build.sh diff --git a/build/setup-wstest.sh b/build/setup-wstest.sh new file mode 100755 index 0000000000..2fb19c5bf3 --- /dev/null +++ b/build/setup-wstest.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +if [ "$TRAVIS_OS_NAME" == "osx" ]; then + # Install python + brew update > /dev/null + brew install python +fi + +type -p python +python --version + +# Install local virtualenv +mkdir .python +cd .python +curl -O https://pypi.python.org/packages/d4/0c/9840c08189e030873387a73b90ada981885010dd9aea134d6de30cd24cb8/virtualenv-15.1.0.tar.gz +tar xf virtualenv-15.1.0.tar.gz +cd .. + +# Make a virtualenv +python ./.python/virtualenv-15.1.0/virtualenv.py .virtualenv + +.virtualenv/bin/python --version +.virtualenv/bin/pip --version + +# Install autobahn into the virtualenv +.virtualenv/bin/pip install autobahntestsuite + +# We're done. The travis config has already established the path to WSTest should be within the virtualenv. +ls -l .virtualenv/bin +.virtualenv/bin/wstest --version \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/AutobahnTester.cs b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/AutobahnTester.cs index c9e6007cb2..bc629e759b 100644 --- a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/AutobahnTester.cs +++ b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/AutobahnTester.cs @@ -43,6 +43,7 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn Spec.WriteJson(specFile); // Run the test (write something to the console so people know this will take a while...) + _logger.LogInformation("Using 'wstest' from: {WsTestPath}", Wstest.Default.Location); _logger.LogInformation("Now launching Autobahn Test Suite. This will take a while."); var exitCode = await Wstest.Default.ExecAsync("-m fuzzingclient -s " + specFile, cancellationToken, _loggerFactory.CreateLogger("wstest")); if (exitCode != 0) diff --git a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/Executable.cs b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/Executable.cs index e012a13dc2..097b600d5a 100644 --- a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/Executable.cs +++ b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/Executable.cs @@ -12,11 +12,11 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn { private static readonly string _exeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty; - private readonly string _path; + public string Location { get; } protected Executable(string path) { - _path = path; + Location = path; } public static string Locate(string name) @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn { StartInfo = new ProcessStartInfo() { - FileName = _path, + FileName = Location, Arguments = args, UseShellExecute = false, RedirectStandardError = true, diff --git a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/Wstest.cs b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/Wstest.cs index bfa2c18af9..a60a91e7c7 100644 --- a/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/Wstest.cs +++ b/test/Microsoft.AspNetCore.WebSockets.ConformanceTest/Autobahn/Wstest.cs @@ -15,7 +15,11 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn private static Wstest Create() { - var location = Locate("wstest"); + var location = Environment.GetEnvironmentVariable("ASPNETCORE_WSTEST_PATH"); + if (string.IsNullOrEmpty(location)) + { + location = Locate("wstest"); + } return location == null ? null : new Wstest(location); } } diff --git a/test/Microsoft.AspNetCore.WebSockets.Test/WebSocketMiddlewareTests.cs b/test/Microsoft.AspNetCore.WebSockets.Test/WebSocketMiddlewareTests.cs index 4034af10a4..cb0d8ec052 100644 --- a/test/Microsoft.AspNetCore.WebSockets.Test/WebSocketMiddlewareTests.cs +++ b/test/Microsoft.AspNetCore.WebSockets.Test/WebSocketMiddlewareTests.cs @@ -16,8 +16,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test private static string ClientAddress = "ws://localhost:54321/"; [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task Connect_Success() { @@ -35,8 +33,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task NegotiateSubProtocol_Success() { @@ -53,14 +49,19 @@ namespace Microsoft.AspNetCore.WebSockets.Test client.Options.AddSubProtocol("bravo"); client.Options.AddSubProtocol("charlie"); await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); - Assert.Equal("Bravo", client.SubProtocol); + + // The Windows version of ClientWebSocket uses the casing from the header (Bravo) + // However, the Managed version seems match the header against the list generated by + // the AddSubProtocol calls (case-insensitively) and then use the version from + // that list as the value for SubProtocol. This is fine, but means we need to ignore case here. + // We could update our AddSubProtocols above to the same case but I think it's better to + // ensure this behavior is codified by this test. + Assert.Equal("Bravo", client.SubProtocol, ignoreCase: true); } } } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task SendEmptyData_Success() { @@ -86,8 +87,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task SendShortData_Success() { @@ -114,8 +113,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task SendMediumData_Success() { @@ -142,8 +139,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task SendLongData_Success() { @@ -182,8 +177,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task SendFragmentedData_Success() { @@ -228,8 +221,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task ReceiveShortData_Success() { @@ -256,8 +247,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task ReceiveMediumData_Success() { @@ -284,8 +273,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] public async Task ReceiveLongData() { @@ -319,223 +306,211 @@ namespace Microsoft.AspNetCore.WebSockets.Test } } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] - public async Task ReceiveFragmentedData_Success() - { - var orriginalData = Encoding.UTF8.GetBytes("Hello World"); - using (var server = KestrelWebSocketHelpers.CreateServer(async context => + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] + public async Task ReceiveFragmentedData_Success() { - Assert.True(context.WebSockets.IsWebSocketRequest); - var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - - await webSocket.SendAsync(new ArraySegment(orriginalData, 0, 2), WebSocketMessageType.Binary, false, CancellationToken.None); - await webSocket.SendAsync(new ArraySegment(orriginalData, 2, 2), WebSocketMessageType.Binary, false, CancellationToken.None); - await webSocket.SendAsync(new ArraySegment(orriginalData, 4, 7), WebSocketMessageType.Binary, true, CancellationToken.None); - })) - { - using (var client = new ClientWebSocket()) + var orriginalData = Encoding.UTF8.GetBytes("Hello World"); + using (var server = KestrelWebSocketHelpers.CreateServer(async context => { - await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); - var clientBuffer = new byte[orriginalData.Length]; - var result = await client.ReceiveAsync(new ArraySegment(clientBuffer), CancellationToken.None); - Assert.False(result.EndOfMessage); - Assert.Equal(2, result.Count); - int totalReceived = result.Count; - Assert.Equal(WebSocketMessageType.Binary, result.MessageType); + Assert.True(context.WebSockets.IsWebSocketRequest); + var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - result = await client.ReceiveAsync( - new ArraySegment(clientBuffer, totalReceived, clientBuffer.Length - totalReceived), CancellationToken.None); - Assert.False(result.EndOfMessage); - Assert.Equal(2, result.Count); - totalReceived += result.Count; - Assert.Equal(WebSocketMessageType.Binary, result.MessageType); + await webSocket.SendAsync(new ArraySegment(orriginalData, 0, 2), WebSocketMessageType.Binary, false, CancellationToken.None); + await webSocket.SendAsync(new ArraySegment(orriginalData, 2, 2), WebSocketMessageType.Binary, false, CancellationToken.None); + await webSocket.SendAsync(new ArraySegment(orriginalData, 4, 7), WebSocketMessageType.Binary, true, CancellationToken.None); + })) + { + using (var client = new ClientWebSocket()) + { + await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); + var clientBuffer = new byte[orriginalData.Length]; + var result = await client.ReceiveAsync(new ArraySegment(clientBuffer), CancellationToken.None); + Assert.False(result.EndOfMessage); + Assert.Equal(2, result.Count); + int totalReceived = result.Count; + Assert.Equal(WebSocketMessageType.Binary, result.MessageType); - result = await client.ReceiveAsync( - new ArraySegment(clientBuffer, totalReceived, clientBuffer.Length - totalReceived), CancellationToken.None); + result = await client.ReceiveAsync( + new ArraySegment(clientBuffer, totalReceived, clientBuffer.Length - totalReceived), CancellationToken.None); + Assert.False(result.EndOfMessage); + Assert.Equal(2, result.Count); + totalReceived += result.Count; + Assert.Equal(WebSocketMessageType.Binary, result.MessageType); + + result = await client.ReceiveAsync( + new ArraySegment(clientBuffer, totalReceived, clientBuffer.Length - totalReceived), CancellationToken.None); + Assert.True(result.EndOfMessage); + Assert.Equal(7, result.Count); + totalReceived += result.Count; + Assert.Equal(WebSocketMessageType.Binary, result.MessageType); + + Assert.Equal(orriginalData, clientBuffer); + } + } + } + + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] + public async Task SendClose_Success() + { + string closeDescription = "Test Closed"; + using (var server = KestrelWebSocketHelpers.CreateServer(async context => + { + Assert.True(context.WebSockets.IsWebSocketRequest); + var webSocket = await context.WebSockets.AcceptWebSocketAsync(); + + var serverBuffer = new byte[1024]; + var result = await webSocket.ReceiveAsync(new ArraySegment(serverBuffer), CancellationToken.None); Assert.True(result.EndOfMessage); - Assert.Equal(7, result.Count); - totalReceived += result.Count; - Assert.Equal(WebSocketMessageType.Binary, result.MessageType); + Assert.Equal(0, result.Count); + Assert.Equal(WebSocketMessageType.Close, result.MessageType); + Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); + Assert.Equal(closeDescription, result.CloseStatusDescription); + })) + { + using (var client = new ClientWebSocket()) + { + await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); + await client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); - Assert.Equal(orriginalData, clientBuffer); + Assert.Equal(WebSocketState.CloseSent, client.State); + } } } - } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] - public async Task SendClose_Success() - { - string closeDescription = "Test Closed"; - using (var server = KestrelWebSocketHelpers.CreateServer(async context => + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] + public async Task ReceiveClose_Success() { - Assert.True(context.WebSockets.IsWebSocketRequest); - var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - - var serverBuffer = new byte[1024]; - var result = await webSocket.ReceiveAsync(new ArraySegment(serverBuffer), CancellationToken.None); - Assert.True(result.EndOfMessage); - Assert.Equal(0, result.Count); - Assert.Equal(WebSocketMessageType.Close, result.MessageType); - Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); - Assert.Equal(closeDescription, result.CloseStatusDescription); - })) - { - using (var client = new ClientWebSocket()) + string closeDescription = "Test Closed"; + using (var server = KestrelWebSocketHelpers.CreateServer(async context => { - await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); - await client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); + Assert.True(context.WebSockets.IsWebSocketRequest); + var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - Assert.Equal(WebSocketState.CloseSent, client.State); + await webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); + })) + { + using (var client = new ClientWebSocket()) + { + await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); + var clientBuffer = new byte[1024]; + var result = await client.ReceiveAsync(new ArraySegment(clientBuffer), CancellationToken.None); + Assert.True(result.EndOfMessage); + Assert.Equal(0, result.Count); + Assert.Equal(WebSocketMessageType.Close, result.MessageType); + Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); + Assert.Equal(closeDescription, result.CloseStatusDescription); + + Assert.Equal(WebSocketState.CloseReceived, client.State); + } } } - } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] - public async Task ReceiveClose_Success() - { - string closeDescription = "Test Closed"; - using (var server = KestrelWebSocketHelpers.CreateServer(async context => + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] + public async Task CloseFromOpen_Success() { - Assert.True(context.WebSockets.IsWebSocketRequest); - var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - - await webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); - })) - { - using (var client = new ClientWebSocket()) + string closeDescription = "Test Closed"; + using (var server = KestrelWebSocketHelpers.CreateServer(async context => { - await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); - var clientBuffer = new byte[1024]; - var result = await client.ReceiveAsync(new ArraySegment(clientBuffer), CancellationToken.None); + Assert.True(context.WebSockets.IsWebSocketRequest); + var webSocket = await context.WebSockets.AcceptWebSocketAsync(); + + var serverBuffer = new byte[1024]; + var result = await webSocket.ReceiveAsync(new ArraySegment(serverBuffer), CancellationToken.None); Assert.True(result.EndOfMessage); Assert.Equal(0, result.Count); Assert.Equal(WebSocketMessageType.Close, result.MessageType); Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); Assert.Equal(closeDescription, result.CloseStatusDescription); - Assert.Equal(WebSocketState.CloseReceived, client.State); + await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); + })) + { + using (var client = new ClientWebSocket()) + { + await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); + await client.CloseAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); + + Assert.Equal(WebSocketState.Closed, client.State); + } } } - } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] - public async Task CloseFromOpen_Success() - { - string closeDescription = "Test Closed"; - using (var server = KestrelWebSocketHelpers.CreateServer(async context => + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] + public async Task CloseFromCloseSent_Success() { - Assert.True(context.WebSockets.IsWebSocketRequest); - var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - - var serverBuffer = new byte[1024]; - var result = await webSocket.ReceiveAsync(new ArraySegment(serverBuffer), CancellationToken.None); - Assert.True(result.EndOfMessage); - Assert.Equal(0, result.Count); - Assert.Equal(WebSocketMessageType.Close, result.MessageType); - Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); - Assert.Equal(closeDescription, result.CloseStatusDescription); - - await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); - })) - { - using (var client = new ClientWebSocket()) + string closeDescription = "Test Closed"; + using (var server = KestrelWebSocketHelpers.CreateServer(async context => { - await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); - await client.CloseAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); + Assert.True(context.WebSockets.IsWebSocketRequest); + var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - Assert.Equal(WebSocketState.Closed, client.State); - } - } - } - - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] - public async Task CloseFromCloseSent_Success() - { - string closeDescription = "Test Closed"; - using (var server = KestrelWebSocketHelpers.CreateServer(async context => - { - Assert.True(context.WebSockets.IsWebSocketRequest); - var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - - var serverBuffer = new byte[1024]; - var result = await webSocket.ReceiveAsync(new ArraySegment(serverBuffer), CancellationToken.None); - Assert.True(result.EndOfMessage); - Assert.Equal(0, result.Count); - Assert.Equal(WebSocketMessageType.Close, result.MessageType); - Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); - Assert.Equal(closeDescription, result.CloseStatusDescription); - - await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); - })) - { - using (var client = new ClientWebSocket()) - { - await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); - await client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); - Assert.Equal(WebSocketState.CloseSent, client.State); - - await client.CloseAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); - Assert.Equal(WebSocketState.Closed, client.State); - } - } - } - - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] - public async Task CloseFromCloseReceived_Success() - { - string closeDescription = "Test Closed"; - using (var server = KestrelWebSocketHelpers.CreateServer(async context => - { - Assert.True(context.WebSockets.IsWebSocketRequest); - var webSocket = await context.WebSockets.AcceptWebSocketAsync(); - - await webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); - - var serverBuffer = new byte[1024]; - var result = await webSocket.ReceiveAsync(new ArraySegment(serverBuffer), CancellationToken.None); - Assert.True(result.EndOfMessage); - Assert.Equal(0, result.Count); - Assert.Equal(WebSocketMessageType.Close, result.MessageType); - Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); - Assert.Equal(closeDescription, result.CloseStatusDescription); - })) - { - using (var client = new ClientWebSocket()) - { - await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); - var clientBuffer = new byte[1024]; - var result = await client.ReceiveAsync(new ArraySegment(clientBuffer), CancellationToken.None); + var serverBuffer = new byte[1024]; + var result = await webSocket.ReceiveAsync(new ArraySegment(serverBuffer), CancellationToken.None); Assert.True(result.EndOfMessage); Assert.Equal(0, result.Count); Assert.Equal(WebSocketMessageType.Close, result.MessageType); Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); Assert.Equal(closeDescription, result.CloseStatusDescription); - Assert.Equal(WebSocketState.CloseReceived, client.State); + await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); + })) + { + using (var client = new ClientWebSocket()) + { + await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); + await client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); + Assert.Equal(WebSocketState.CloseSent, client.State); - await client.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); + await client.CloseAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); + Assert.Equal(WebSocketState.Closed, client.State); + } + } + } - Assert.Equal(WebSocketState.Closed, client.State); + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")] + public async Task CloseFromCloseReceived_Success() + { + string closeDescription = "Test Closed"; + using (var server = KestrelWebSocketHelpers.CreateServer(async context => + { + Assert.True(context.WebSockets.IsWebSocketRequest); + var webSocket = await context.WebSockets.AcceptWebSocketAsync(); + + await webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); + + var serverBuffer = new byte[1024]; + var result = await webSocket.ReceiveAsync(new ArraySegment(serverBuffer), CancellationToken.None); + Assert.True(result.EndOfMessage); + Assert.Equal(0, result.Count); + Assert.Equal(WebSocketMessageType.Close, result.MessageType); + Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); + Assert.Equal(closeDescription, result.CloseStatusDescription); + })) + { + using (var client = new ClientWebSocket()) + { + await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); + var clientBuffer = new byte[1024]; + var result = await client.ReceiveAsync(new ArraySegment(clientBuffer), CancellationToken.None); + Assert.True(result.EndOfMessage); + Assert.Equal(0, result.Count); + Assert.Equal(WebSocketMessageType.Close, result.MessageType); + Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); + Assert.Equal(closeDescription, result.CloseStatusDescription); + + Assert.Equal(WebSocketState.CloseReceived, client.State); + + await client.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); + + Assert.Equal(WebSocketState.Closed, client.State); + } } } } } -}