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

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);
// 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)

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

View File

@ -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);
}
}

View File

@ -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<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())
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<byte>(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<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);
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);
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(
new ArraySegment<byte>(clientBuffer, totalReceived, clientBuffer.Length - totalReceived), CancellationToken.None);
result = await client.ReceiveAsync(
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.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<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())
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<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]
[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<byte>(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<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);
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<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())
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<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);
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);
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);
}
}
}
}
}
}