Skip to content

Commit

Permalink
Merge branch 'release' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
NTaylorMullen committed Oct 31, 2013
2 parents 82d30f7 + 5fa9002 commit 9ca08ec
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ protected override void OnStart(IConnection connection,

private void Reconnect(IConnection connection, string data, CancellationToken disconnectToken)
{
// Need to verify before the task delay occurs because an application sleep could occur during the delayed duration.
if (!TransportHelper.VerifyReconnect(connection))
{
return;
}

// Wait for a bit before reconnecting
TaskAsyncHelper.Delay(ReconnectDelay).Then(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,54 @@ namespace Microsoft.AspNet.SignalR.Tests

public class ConnectionFacts : HostedTest
{
[Theory]
[InlineData(HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData(HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Fake)]
[InlineData(HostType.Memory, TransportType.ServerSentEvents, MessageBusType.FakeMultiStream)]
[InlineData(HostType.Memory, TransportType.LongPolling, MessageBusType.Default)]
[InlineData(HostType.Memory, TransportType.LongPolling, MessageBusType.Fake)]
[InlineData(HostType.Memory, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
[InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
[InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
[InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
[InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.Default)]
public void ReconnectExceedingReconnectWindowDisconnectsWithFastBeatInterval(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
// Test cannot be async because if we do host.ShutDown() after an await the connection stops.

using (var host = CreateHost(hostType, transportType))
{
host.Initialize(keepAlive: 9, messageBusType: messageBusType);
var connection = CreateHubConnection(host);

using (connection)
{
var disconnectWh = new ManualResetEventSlim();

connection.Closed += () =>
{
disconnectWh.Set();
};

SetReconnectDelay(host.Transport, TimeSpan.FromSeconds(15));

connection.Start(host.Transport).Wait();

// Set reconnect window to zero so the second we attempt to reconnect we can ensure that the reconnect window is verified.
((Client.IConnection)connection).ReconnectWindow = TimeSpan.FromSeconds(0);

// Without this the connection start and reconnect can race with eachother resulting in a deadlock.
Thread.Sleep(TimeSpan.FromSeconds(3));

host.Shutdown();

Assert.True(disconnectWh.Wait(TimeSpan.FromSeconds(15)), "Closed never fired");
}
}
}

[Theory]
[InlineData(HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData(HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Fake)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ protected void UseMessageBus(MessageBusType type, IDependencyResolver resolver,
}
}

protected void SetReconnectDelay(IClientTransport transport, TimeSpan delay)
{
// SUPER ugly, alternative is adding an overload to the create host function, adding a member to the
// IClientTransport object or using Reflection. Adding a member to IClientTransport isn't horrible
// but we want to avoid making a breaking change... Therefore this is the least of the evils.
if (transport is ServerSentEventsTransport)
{
(transport as ServerSentEventsTransport).ReconnectDelay = delay;
}
else if (transport is LongPollingTransport)
{
(transport as LongPollingTransport).ReconnectDelay = delay;
}
else if (transport is WebSocketTransport)
{
(transport as WebSocketTransport).ReconnectDelay = delay;
}
}

protected void EnableTracing()
{
string testName = GetTestName() + "." + Interlocked.Increment(ref _id);
Expand Down

0 comments on commit 9ca08ec

Please sign in to comment.