Merge pull request #1788 from aspnet/release/2.1

Check for Websockets in Fallback functional tests (#1772)
This commit is contained in:
Mikael Mengistu 2018-03-30 12:38:58 -07:00 committed by GitHub
commit 81b0f60b5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 42 deletions

View File

@ -9,6 +9,7 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Client.Tests;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.SignalR.Tests;
using Microsoft.AspNetCore.Sockets.Client.Http;
using Microsoft.AspNetCore.Sockets.Client.Internal;
using Microsoft.Extensions.Logging.Testing;
@ -94,7 +95,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
// with WebSockets available and not. If Websockets aren't available and
// we can't to test the fallback once scenario we don't decrement the passthreshold
// because we still try to start twice (SSE and LP).
if (!IsWebSocketsSupported() && passThreshold > 2)
if (!TestHelpers.IsWebSocketsSupported() && passThreshold > 2)
{
passThreshold -= 1;
}
@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
Assert.Equal("Unable to connect to the server with any of the available transports.", ex.Message);
// If websockets aren't supported then we expect one less attmept to start.
if (!IsWebSocketsSupported())
if (!TestHelpers.IsWebSocketsSupported())
{
availableTransports -= 1;
}
@ -363,23 +364,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
await Assert.ThrowsAsync<ObjectDisposedException>(() => connection.StartAsync(TransferFormat.Text).OrTimeout());
Assert.Equal(nameof(HttpConnection), exception.ObjectName);
}
private static bool IsWebSocketsSupported()
{
#if NETCOREAPP2_1
// .NET Core 2.1 and greater has sockets
return true;
#else
// Non-Windows platforms have sockets
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return true;
}
// Windows 8 and greater has sockets
return Environment.OSVersion.Version >= new Version(6, 2);
#endif
}
}
}
}

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.AspNetCore.SignalR.Tests
{
@ -9,16 +10,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{
public static bool IsWebSocketsSupported()
{
try
{
new System.Net.WebSockets.ClientWebSocket().Dispose();
}
catch (PlatformNotSupportedException)
{
return false;
}
#if NETCOREAPP2_1
// .NET Core 2.1 and greater has sockets
return true;
#else
// Non-Windows platforms have sockets
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return true;
}
// Windows 8 and greater has sockets
return Environment.OSVersion.Version >= new Version(6, 2);
#endif
}
}
}

View File

@ -16,19 +16,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{
get
{
#if NETCOREAPP2_1
// .NET Core 2.1 and greater has sockets
return true;
#else
// Non-Windows platforms have Websockets
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return true;
}
// Windows 8 and greater has Websockets
return Environment.OSVersion.Version >= new Version(6, 2);
#endif
return TestHelpers.IsWebSocketsSupported();
}
}

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO.Pipelines;
using System.Net.Http;
using System.Net.WebSockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -408,6 +409,15 @@ namespace Microsoft.AspNetCore.SignalR.Tests
private int _tries;
private string _prevConnectionId = null;
private IDuplexPipe _application;
private int availableTransports = 3;
public FakeTransport()
{
if (!TestHelpers.IsWebSocketsSupported())
{
availableTransports -= 1;
}
}
public Task StartAsync(Uri url, IDuplexPipe application, TransferFormat transferFormat, IConnection connection)
{
@ -424,7 +434,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
_prevConnectionId = id;
}
if (_tries < 3)
if (_tries < availableTransports)
{
throw new Exception();
}