Enabling tests which would have prevented a bug
This commit is contained in:
parent
e8a673248a
commit
9eabce1b02
|
|
@ -120,6 +120,14 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
? (IDataEncoder)Base64Encoder
|
? (IDataEncoder)Base64Encoder
|
||||||
: PassThroughEncoder;
|
: PassThroughEncoder;
|
||||||
|
|
||||||
|
var transferModeFeature = connection.Features.Get<ITransferModeFeature>() ??
|
||||||
|
throw new InvalidOperationException("Unable to read transfer mode.");
|
||||||
|
|
||||||
|
transferModeFeature.TransferMode =
|
||||||
|
(protocol.Type == ProtocolType.Binary && (transportCapabilities & TransferMode.Binary) != 0)
|
||||||
|
? TransferMode.Binary
|
||||||
|
: TransferMode.Text;
|
||||||
|
|
||||||
connection.ProtocolReaderWriter = new HubProtocolReaderWriter(protocol, dataEncoder);
|
connection.ProtocolReaderWriter = new HubProtocolReaderWriter(protocol, dataEncoder);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(HubProtocolsXTransportsXHubPaths))]
|
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
|
||||||
public async Task CheckFixedMessage(IHubProtocol protocol, TransportType transportType, string path)
|
public async Task CheckFixedMessage(IHubProtocol protocol, TransportType transportType, string path)
|
||||||
{
|
{
|
||||||
using (StartLog(out var loggerFactory))
|
using (StartLog(out var loggerFactory))
|
||||||
|
|
@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(HubProtocolsXTransportsXHubPaths))]
|
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
|
||||||
public async Task CanSendAndReceiveMessage(IHubProtocol protocol, TransportType transportType, string path)
|
public async Task CanSendAndReceiveMessage(IHubProtocol protocol, TransportType transportType, string path)
|
||||||
{
|
{
|
||||||
using (StartLog(out var loggerFactory))
|
using (StartLog(out var loggerFactory))
|
||||||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(HubProtocolsXTransportsXHubPaths))]
|
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
|
||||||
public async Task MethodsAreCaseInsensitive(IHubProtocol protocol, TransportType transportType, string path)
|
public async Task MethodsAreCaseInsensitive(IHubProtocol protocol, TransportType transportType, string path)
|
||||||
{
|
{
|
||||||
using (StartLog(out var loggerFactory))
|
using (StartLog(out var loggerFactory))
|
||||||
|
|
@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(HubProtocolsXTransportsXHubPaths))]
|
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
|
||||||
public async Task CanInvokeClientMethodFromServer(IHubProtocol protocol, TransportType transportType, string path)
|
public async Task CanInvokeClientMethodFromServer(IHubProtocol protocol, TransportType transportType, string path)
|
||||||
{
|
{
|
||||||
using (StartLog(out var loggerFactory))
|
using (StartLog(out var loggerFactory))
|
||||||
|
|
@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(HubProtocolsXTransportsXHubPaths))]
|
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
|
||||||
public async Task CanStreamClientMethodFromServer(IHubProtocol protocol, TransportType transportType, string path)
|
public async Task CanStreamClientMethodFromServer(IHubProtocol protocol, TransportType transportType, string path)
|
||||||
{
|
{
|
||||||
using (StartLog(out var loggerFactory))
|
using (StartLog(out var loggerFactory))
|
||||||
|
|
@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(HubProtocolsXTransportsXHubPaths))]
|
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
|
||||||
public async Task ServerClosesConnectionIfHubMethodCannotBeResolved(IHubProtocol hubProtocol, TransportType transportType, string hubPath)
|
public async Task ServerClosesConnectionIfHubMethodCannotBeResolved(IHubProtocol hubProtocol, TransportType transportType, string hubPath)
|
||||||
{
|
{
|
||||||
using (StartLog(out var loggerFactory))
|
using (StartLog(out var loggerFactory))
|
||||||
|
|
@ -217,15 +217,18 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> HubProtocolsXTransportsXHubPaths()
|
public static IEnumerable<object[]> HubProtocolsAndTransportsAndHubPaths
|
||||||
{
|
{
|
||||||
foreach (var protocol in HubProtocols)
|
get
|
||||||
{
|
{
|
||||||
foreach (var transport in TransportTypes())
|
foreach (var protocol in HubProtocols)
|
||||||
{
|
{
|
||||||
foreach (var hubPath in HubPaths)
|
foreach (var transport in TransportTypes())
|
||||||
{
|
{
|
||||||
yield return new object[] { protocol, transport, hubPath };
|
foreach (var hubPath in HubPaths)
|
||||||
|
{
|
||||||
|
yield return new object[] { protocol, transport, hubPath };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -240,16 +243,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
new MessagePackHubProtocol(),
|
new MessagePackHubProtocol(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public static IEnumerable<TransportType> TransportTypes()
|
public static IEnumerable<TransportType> TransportTypes()
|
||||||
{
|
{
|
||||||
if (TestHelpers.IsWebSocketsSupported())
|
if (TestHelpers.IsWebSocketsSupported())
|
||||||
{
|
{
|
||||||
// TODO: Currently we are always sending Text messages over websockets which does not work
|
yield return TransportType.WebSockets;
|
||||||
// with binary protocols. It is getting fixed separately.
|
|
||||||
// The tests are also failing on full framework when using WebSockets transport
|
|
||||||
// due to: https://github.com/aspnet/SignalR/issues/568
|
|
||||||
// yield return TransportType.WebSockets;
|
|
||||||
}
|
}
|
||||||
yield return TransportType.ServerSentEvents;
|
yield return TransportType.ServerSentEvents;
|
||||||
yield return TransportType.LongPolling;
|
yield return TransportType.LongPolling;
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalTheory]
|
[Theory]
|
||||||
[MemberData(nameof(TransportTypes))]
|
[MemberData(nameof(TransportTypesAndTransferModes))]
|
||||||
// TODO: transfer types
|
public async Task ConnectionCanSendAndReceiveMessages(TransportType transportType, TransferMode requestedTransferMode)
|
||||||
public async Task ConnectionCanSendAndReceiveMessages(TransportType transportType)
|
|
||||||
{
|
{
|
||||||
using (StartLog(out var loggerFactory, testName: $"ConnectionCanSendAndReceiveMessages_{transportType.ToString()}"))
|
using (StartLog(out var loggerFactory, testName: $"ConnectionCanSendAndReceiveMessages_{transportType.ToString()}"))
|
||||||
{
|
{
|
||||||
|
|
@ -112,7 +111,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);
|
var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);
|
||||||
|
|
||||||
connection.Features.Set<ITransferModeFeature>(
|
connection.Features.Set<ITransferModeFeature>(
|
||||||
new TransferModeFeature { TransferMode = TransferMode.Text });
|
new TransferModeFeature { TransferMode = requestedTransferMode });
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var receiveTcs = new TaskCompletionSource<string>();
|
var receiveTcs = new TaskCompletionSource<string>();
|
||||||
|
|
@ -120,6 +119,12 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
connection.Received += data =>
|
connection.Received += data =>
|
||||||
{
|
{
|
||||||
logger.LogInformation("Received {length} byte message", data.Length);
|
logger.LogInformation("Received {length} byte message", data.Length);
|
||||||
|
|
||||||
|
if (IsBase64Encoded(requestedTransferMode, connection))
|
||||||
|
{
|
||||||
|
data = Convert.FromBase64String(Encoding.UTF8.GetString(data));
|
||||||
|
}
|
||||||
|
|
||||||
receiveTcs.TrySetResult(Encoding.UTF8.GetString(data));
|
receiveTcs.TrySetResult(Encoding.UTF8.GetString(data));
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
@ -144,6 +149,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
logger.LogInformation("Started connection to {url}", url);
|
logger.LogInformation("Started connection to {url}", url);
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes(message);
|
var bytes = Encoding.UTF8.GetBytes(message);
|
||||||
|
|
||||||
|
// Need to encode binary payloads sent over text transports
|
||||||
|
if (IsBase64Encoded(requestedTransferMode, connection))
|
||||||
|
{
|
||||||
|
bytes = Encoding.UTF8.GetBytes(Convert.ToBase64String(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
logger.LogInformation("Sending {length} byte message", bytes.Length);
|
logger.LogInformation("Sending {length} byte message", bytes.Length);
|
||||||
await connection.SendAsync(bytes).OrTimeout();
|
await connection.SendAsync(bytes).OrTimeout();
|
||||||
logger.LogInformation("Sent message", bytes.Length);
|
logger.LogInformation("Sent message", bytes.Length);
|
||||||
|
|
@ -166,6 +178,12 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
logger.LogInformation("Disposed Connection");
|
logger.LogInformation("Disposed Connection");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsBase64Encoded(TransferMode transferMode, IConnection connection)
|
||||||
|
{
|
||||||
|
return requestedTransferMode == TransferMode.Binary &&
|
||||||
|
connection.Features.Get<ITransferModeFeature>().TransferMode == TransferMode.Text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> MessageSizesData
|
public static IEnumerable<object[]> MessageSizesData
|
||||||
|
|
@ -292,14 +310,29 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> TransportTypes()
|
public static IEnumerable<object[]> TransportTypes
|
||||||
{
|
{
|
||||||
if (TestHelpers.IsWebSocketsSupported())
|
get
|
||||||
{
|
{
|
||||||
yield return new object[] { TransportType.WebSockets };
|
if (TestHelpers.IsWebSocketsSupported())
|
||||||
|
{
|
||||||
|
yield return new object[] { TransportType.WebSockets };
|
||||||
|
}
|
||||||
|
yield return new object[] { TransportType.ServerSentEvents };
|
||||||
|
yield return new object[] { TransportType.LongPolling };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> TransportTypesAndTransferModes
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
foreach (var transport in TransportTypes)
|
||||||
|
{
|
||||||
|
yield return new object[] { transport[0], TransferMode.Text };
|
||||||
|
yield return new object[] { transport[0], TransferMode.Binary };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
yield return new object[] { TransportType.ServerSentEvents };
|
|
||||||
yield return new object[] { TransportType.LongPolling };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue