Merge pull request #1788 from aspnet/release/2.1
Check for Websockets in Fallback functional tests (#1772)
This commit is contained in:
commit
81b0f60b5a
|
|
@ -9,6 +9,7 @@ using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Client.Tests;
|
using Microsoft.AspNetCore.Client.Tests;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
|
using Microsoft.AspNetCore.SignalR.Tests;
|
||||||
using Microsoft.AspNetCore.Sockets.Client.Http;
|
using Microsoft.AspNetCore.Sockets.Client.Http;
|
||||||
using Microsoft.AspNetCore.Sockets.Client.Internal;
|
using Microsoft.AspNetCore.Sockets.Client.Internal;
|
||||||
using Microsoft.Extensions.Logging.Testing;
|
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
|
// 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
|
// 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).
|
// because we still try to start twice (SSE and LP).
|
||||||
if (!IsWebSocketsSupported() && passThreshold > 2)
|
if (!TestHelpers.IsWebSocketsSupported() && passThreshold > 2)
|
||||||
{
|
{
|
||||||
passThreshold -= 1;
|
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);
|
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 websockets aren't supported then we expect one less attmept to start.
|
||||||
if (!IsWebSocketsSupported())
|
if (!TestHelpers.IsWebSocketsSupported())
|
||||||
{
|
{
|
||||||
availableTransports -= 1;
|
availableTransports -= 1;
|
||||||
}
|
}
|
||||||
|
|
@ -363,23 +364,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(() => connection.StartAsync(TransferFormat.Text).OrTimeout());
|
await Assert.ThrowsAsync<ObjectDisposedException>(() => connection.StartAsync(TransferFormat.Text).OrTimeout());
|
||||||
Assert.Equal(nameof(HttpConnection), exception.ObjectName);
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
{
|
{
|
||||||
|
|
@ -9,16 +10,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
{
|
{
|
||||||
public static bool IsWebSocketsSupported()
|
public static bool IsWebSocketsSupported()
|
||||||
{
|
{
|
||||||
try
|
#if NETCOREAPP2_1
|
||||||
{
|
// .NET Core 2.1 and greater has sockets
|
||||||
new System.Net.WebSockets.ClientWebSocket().Dispose();
|
|
||||||
}
|
|
||||||
catch (PlatformNotSupportedException)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
#if NETCOREAPP2_1
|
return TestHelpers.IsWebSocketsSupported();
|
||||||
// .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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.IO.Pipelines;
|
using System.IO.Pipelines;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -408,6 +409,15 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
private int _tries;
|
private int _tries;
|
||||||
private string _prevConnectionId = null;
|
private string _prevConnectionId = null;
|
||||||
private IDuplexPipe _application;
|
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)
|
public Task StartAsync(Uri url, IDuplexPipe application, TransferFormat transferFormat, IConnection connection)
|
||||||
{
|
{
|
||||||
|
|
@ -424,7 +434,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
_prevConnectionId = id;
|
_prevConnectionId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_tries < 3)
|
if (_tries < availableTransports)
|
||||||
{
|
{
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue