Increase timeout of test (#2021)
- Seems like it was possible for the server timeout to happen *before* the invocation happened. - Added logging to the test
This commit is contained in:
parent
d6395a52bc
commit
4fe41dc6d0
|
|
@ -1,12 +1,13 @@
|
||||||
using Microsoft.AspNetCore.SignalR.Protocol;
|
using Microsoft.AspNetCore.SignalR.Protocol;
|
||||||
using Microsoft.AspNetCore.SignalR.Tests;
|
using Microsoft.AspNetCore.SignalR.Tests;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
{
|
{
|
||||||
public partial class HubConnectionTests
|
public partial class HubConnectionTests
|
||||||
{
|
{
|
||||||
private static HubConnection CreateHubConnection(TestConnection connection, IHubProtocol protocol = null)
|
private static HubConnection CreateHubConnection(TestConnection connection, IHubProtocol protocol = null, ILoggerFactory loggerFactory = null)
|
||||||
{
|
{
|
||||||
var builder = new HubConnectionBuilder();
|
var builder = new HubConnectionBuilder();
|
||||||
|
|
||||||
|
|
@ -16,6 +17,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
|
|
||||||
builder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);
|
builder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);
|
||||||
|
|
||||||
|
if (loggerFactory != null)
|
||||||
|
{
|
||||||
|
builder.WithLoggerFactory(loggerFactory);
|
||||||
|
}
|
||||||
|
|
||||||
if (protocol != null)
|
if (protocol != null)
|
||||||
{
|
{
|
||||||
builder.Services.AddSingleton(protocol);
|
builder.Services.AddSingleton(protocol);
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,21 @@ using Microsoft.AspNetCore.Connections;
|
||||||
using Microsoft.AspNetCore.SignalR.Protocol;
|
using Microsoft.AspNetCore.SignalR.Protocol;
|
||||||
using Microsoft.AspNetCore.SignalR.Tests;
|
using Microsoft.AspNetCore.SignalR.Tests;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
{
|
{
|
||||||
public partial class HubConnectionTests
|
public partial class HubConnectionTests : LoggedTest
|
||||||
{
|
{
|
||||||
|
public HubConnectionTests(ITestOutputHelper output)
|
||||||
|
: base(output)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task InvokeThrowsIfSerializingMessageFails()
|
public async Task InvokeThrowsIfSerializingMessageFails()
|
||||||
{
|
{
|
||||||
|
|
@ -112,16 +120,19 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PendingInvocationsAreTerminatedIfServerTimeoutIntervalElapsesWithNoMessages()
|
public async Task PendingInvocationsAreTerminatedIfServerTimeoutIntervalElapsesWithNoMessages()
|
||||||
{
|
{
|
||||||
var hubConnection = CreateHubConnection(new TestConnection());
|
using (StartLog(out var loggerFactory, LogLevel.Trace))
|
||||||
hubConnection.ServerTimeout = TimeSpan.FromMilliseconds(500);
|
{
|
||||||
|
var hubConnection = CreateHubConnection(new TestConnection(), loggerFactory: loggerFactory);
|
||||||
|
hubConnection.ServerTimeout = TimeSpan.FromMilliseconds(2000);
|
||||||
|
|
||||||
await hubConnection.StartAsync().OrTimeout();
|
await hubConnection.StartAsync().OrTimeout();
|
||||||
|
|
||||||
// Start an invocation (but we won't complete it)
|
// Start an invocation (but we won't complete it)
|
||||||
var invokeTask = hubConnection.InvokeAsync("Method").OrTimeout();
|
var invokeTask = hubConnection.InvokeAsync("Method").OrTimeout();
|
||||||
|
|
||||||
var exception = await Assert.ThrowsAsync<TimeoutException>(() => invokeTask);
|
var exception = await Assert.ThrowsAsync<TimeoutException>(() => invokeTask);
|
||||||
Assert.Equal("Server timeout (500.00ms) elapsed without receiving a message from the server.", exception.Message);
|
Assert.Equal("Server timeout (2000.00ms) elapsed without receiving a message from the server.", exception.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moq really doesn't handle out parameters well, so to make these tests work I added a manual mock -anurse
|
// Moq really doesn't handle out parameters well, so to make these tests work I added a manual mock -anurse
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue