Unbreak Travis and unskip some tests (#219)

This commit is contained in:
Andrew Stanton-Nurse 2018-01-05 12:39:11 -08:00 committed by GitHub
parent de3355454c
commit d3687bbc3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 217 additions and 208 deletions

View File

@ -6,9 +6,10 @@ env:
- 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 - AUTOBAHN_SUITES_LOG: 1
- ASPNETCORE_WSTEST_PATH: "$TRAVIS_BUILD_DIR/.virtualenv/bin/wstest"
mono: none mono: none
python: python:
- "2.7" - pypy
os: os:
- linux - linux
- osx - osx
@ -23,9 +24,7 @@ branches:
- release - release
- dev - dev
- /^(.*\/)?ci-.*$/ - /^(.*\/)?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: install:
- pip install autobahntestsuite "six>=1.9.0" - ./build/setup-wstest.sh
script: script:
- ./build.sh - ./build.sh

30
build/setup-wstest.sh Executable file
View File

@ -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

View File

@ -43,6 +43,7 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
Spec.WriteJson(specFile); Spec.WriteJson(specFile);
// Run the test (write something to the console so people know this will take a while...) // 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."); _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")); var exitCode = await Wstest.Default.ExecAsync("-m fuzzingclient -s " + specFile, cancellationToken, _loggerFactory.CreateLogger("wstest"));
if (exitCode != 0) if (exitCode != 0)

View File

@ -12,11 +12,11 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
{ {
private static readonly string _exeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty; private static readonly string _exeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;
private readonly string _path; public string Location { get; }
protected Executable(string path) protected Executable(string path)
{ {
_path = path; Location = path;
} }
public static string Locate(string name) public static string Locate(string name)
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
{ {
StartInfo = new ProcessStartInfo() StartInfo = new ProcessStartInfo()
{ {
FileName = _path, FileName = Location,
Arguments = args, Arguments = args,
UseShellExecute = false, UseShellExecute = false,
RedirectStandardError = true, RedirectStandardError = true,

View File

@ -15,7 +15,11 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
private static Wstest Create() 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); return location == null ? null : new Wstest(location);
} }
} }

View File

@ -16,8 +16,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
private static string ClientAddress = "ws://localhost:54321/"; private static string ClientAddress = "ws://localhost:54321/";
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task Connect_Success() public async Task Connect_Success()
{ {
@ -35,8 +33,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task NegotiateSubProtocol_Success() public async Task NegotiateSubProtocol_Success()
{ {
@ -53,14 +49,19 @@ namespace Microsoft.AspNetCore.WebSockets.Test
client.Options.AddSubProtocol("bravo"); client.Options.AddSubProtocol("bravo");
client.Options.AddSubProtocol("charlie"); client.Options.AddSubProtocol("charlie");
await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); 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] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task SendEmptyData_Success() public async Task SendEmptyData_Success()
{ {
@ -86,8 +87,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task SendShortData_Success() public async Task SendShortData_Success()
{ {
@ -114,8 +113,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task SendMediumData_Success() public async Task SendMediumData_Success()
{ {
@ -142,8 +139,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task SendLongData_Success() public async Task SendLongData_Success()
{ {
@ -182,8 +177,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task SendFragmentedData_Success() public async Task SendFragmentedData_Success()
{ {
@ -228,8 +221,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task ReceiveShortData_Success() public async Task ReceiveShortData_Success()
{ {
@ -256,8 +247,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task ReceiveMediumData_Success() public async Task ReceiveMediumData_Success()
{ {
@ -284,8 +273,6 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
[ConditionalFact] [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")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
public async Task ReceiveLongData() public async Task ReceiveLongData()
{ {
@ -319,223 +306,211 @@ namespace Microsoft.AspNetCore.WebSockets.Test
} }
} }
[ConditionalFact] [ConditionalFact]
[OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
[OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] public async Task ReceiveFragmentedData_Success()
[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 =>
{ {
Assert.True(context.WebSockets.IsWebSocketRequest); var orriginalData = Encoding.UTF8.GetBytes("Hello World");
var webSocket = await context.WebSockets.AcceptWebSocketAsync(); using (var server = KestrelWebSocketHelpers.CreateServer(async context =>
await webSocket.SendAsync(new ArraySegment<byte>(orriginalData, 0, 2), WebSocketMessageType.Binary, false, CancellationToken.None);
await webSocket.SendAsync(new ArraySegment<byte>(orriginalData, 2, 2), WebSocketMessageType.Binary, false, CancellationToken.None);
await webSocket.SendAsync(new ArraySegment<byte>(orriginalData, 4, 7), WebSocketMessageType.Binary, true, CancellationToken.None);
}))
{
using (var client = new ClientWebSocket())
{ {
await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); Assert.True(context.WebSockets.IsWebSocketRequest);
var clientBuffer = new byte[orriginalData.Length]; var webSocket = await context.WebSockets.AcceptWebSocketAsync();
var result = await client.ReceiveAsync(new ArraySegment<byte>(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( await webSocket.SendAsync(new ArraySegment<byte>(orriginalData, 0, 2), WebSocketMessageType.Binary, false, CancellationToken.None);
new ArraySegment<byte>(clientBuffer, totalReceived, clientBuffer.Length - totalReceived), CancellationToken.None); await webSocket.SendAsync(new ArraySegment<byte>(orriginalData, 2, 2), WebSocketMessageType.Binary, false, CancellationToken.None);
Assert.False(result.EndOfMessage); await webSocket.SendAsync(new ArraySegment<byte>(orriginalData, 4, 7), WebSocketMessageType.Binary, true, CancellationToken.None);
Assert.Equal(2, result.Count); }))
totalReceived += result.Count; {
Assert.Equal(WebSocketMessageType.Binary, result.MessageType); 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<byte>(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( result = await client.ReceiveAsync(
new ArraySegment<byte>(clientBuffer, totalReceived, clientBuffer.Length - totalReceived), CancellationToken.None); new ArraySegment<byte>(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<byte>(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<byte>(serverBuffer), CancellationToken.None);
Assert.True(result.EndOfMessage); Assert.True(result.EndOfMessage);
Assert.Equal(7, result.Count); Assert.Equal(0, result.Count);
totalReceived += result.Count; Assert.Equal(WebSocketMessageType.Close, result.MessageType);
Assert.Equal(WebSocketMessageType.Binary, 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] [ConditionalFact]
[OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
[OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] public async Task ReceiveClose_Success()
[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); string closeDescription = "Test Closed";
var webSocket = await context.WebSockets.AcceptWebSocketAsync(); using (var server = KestrelWebSocketHelpers.CreateServer(async context =>
var serverBuffer = new byte[1024];
var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(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); Assert.True(context.WebSockets.IsWebSocketRequest);
await client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); 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<byte>(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] [ConditionalFact]
[OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
[OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] public async Task CloseFromOpen_Success()
[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 =>
{ {
Assert.True(context.WebSockets.IsWebSocketRequest); string closeDescription = "Test Closed";
var webSocket = await context.WebSockets.AcceptWebSocketAsync(); using (var server = KestrelWebSocketHelpers.CreateServer(async context =>
await webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None);
}))
{
using (var client = new ClientWebSocket())
{ {
await client.ConnectAsync(new Uri(ClientAddress), CancellationToken.None); Assert.True(context.WebSockets.IsWebSocketRequest);
var clientBuffer = new byte[1024]; var webSocket = await context.WebSockets.AcceptWebSocketAsync();
var result = await client.ReceiveAsync(new ArraySegment<byte>(clientBuffer), CancellationToken.None);
var serverBuffer = new byte[1024];
var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(serverBuffer), CancellationToken.None);
Assert.True(result.EndOfMessage); Assert.True(result.EndOfMessage);
Assert.Equal(0, result.Count); Assert.Equal(0, result.Count);
Assert.Equal(WebSocketMessageType.Close, result.MessageType); Assert.Equal(WebSocketMessageType.Close, result.MessageType);
Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus);
Assert.Equal(closeDescription, result.CloseStatusDescription); 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] [ConditionalFact]
[OSSkipCondition(OperatingSystems.Linux, SkipReason = "No WebSockets Client for this platform")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "No WebSockets Client for this platform")]
[OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "No WebSockets Client for this platform")] public async Task CloseFromCloseSent_Success()
[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 =>
{ {
Assert.True(context.WebSockets.IsWebSocketRequest); string closeDescription = "Test Closed";
var webSocket = await context.WebSockets.AcceptWebSocketAsync(); using (var server = KestrelWebSocketHelpers.CreateServer(async context =>
var serverBuffer = new byte[1024];
var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(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); Assert.True(context.WebSockets.IsWebSocketRequest);
await client.CloseAsync(WebSocketCloseStatus.NormalClosure, closeDescription, CancellationToken.None); var webSocket = await context.WebSockets.AcceptWebSocketAsync();
Assert.Equal(WebSocketState.Closed, client.State); var serverBuffer = new byte[1024];
} var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(serverBuffer), CancellationToken.None);
}
}
[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<byte>(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<byte>(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<byte>(clientBuffer), CancellationToken.None);
Assert.True(result.EndOfMessage); Assert.True(result.EndOfMessage);
Assert.Equal(0, result.Count); Assert.Equal(0, result.Count);
Assert.Equal(WebSocketMessageType.Close, result.MessageType); Assert.Equal(WebSocketMessageType.Close, result.MessageType);
Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus);
Assert.Equal(closeDescription, result.CloseStatusDescription); 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<byte>(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<byte>(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);
}
} }
} }
} }
} }
}