Skip to content

Commit

Permalink
Merge branch 'release' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
abnanda1 committed Dec 10, 2013
2 parents 669975f + 002865f commit 4e43c65
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/Microsoft.AspNet.SignalR.Client/Connection.cs
Expand Up @@ -42,6 +42,9 @@ public class Connection : IConnection, IDisposable
// The amount of time the client should attempt to reconnect before stopping.
private TimeSpan _disconnectTimeout;

// The amount of time a transport will wait (while connecting) before failing.
private TimeSpan _totalTransportConnectTimeout;

// Provides a way to cancel the the timeout that stops a reconnect cycle
private IDisposable _disconnectTimeoutOperation;

Expand Down Expand Up @@ -176,6 +179,7 @@ public Connection(string url, string queryString)
TraceWriter = new DebugTextWriter();
Headers = new HeaderDictionary(this);
TransportConnectTimeout = TimeSpan.Zero;
_totalTransportConnectTimeout = TimeSpan.Zero;

// Current client protocol
Protocol = new Version(1, 3);
Expand All @@ -187,6 +191,18 @@ public Connection(string url, string queryString)
/// </summary>
public TimeSpan TransportConnectTimeout { get; set; }

/// <summary>
/// The amount of time a transport will wait (while connecting) before failing.
/// This is the total vaue obtained by adding the server's configuration value and the timeout specified by the user
/// </summary>
TimeSpan IConnection.TotalTransportConnectTimeout
{
get
{
return _totalTransportConnectTimeout;
}
}

public Version Protocol { get; set; }

/// <summary>
Expand Down Expand Up @@ -446,7 +462,7 @@ private Task Negotiate(IClientTransport transport)
ConnectionId = negotiationResponse.ConnectionId;
ConnectionToken = negotiationResponse.ConnectionToken;
_disconnectTimeout = TimeSpan.FromSeconds(negotiationResponse.DisconnectTimeout);
TransportConnectTimeout = TransportConnectTimeout + TimeSpan.FromSeconds(negotiationResponse.TransportConnectTimeout);
_totalTransportConnectTimeout = TransportConnectTimeout + TimeSpan.FromSeconds(negotiationResponse.TransportConnectTimeout);
// Default the beat interval to be 5 seconds in case keep alive is disabled.
var beatInterval = TimeSpan.FromSeconds(5);
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.AspNet.SignalR.Client/IConnection.cs
Expand Up @@ -21,6 +21,7 @@ public interface IConnection
{
Version Protocol { get; set; }
TimeSpan TransportConnectTimeout { get; set; }
TimeSpan TotalTransportConnectTimeout { get; }
TimeSpan ReconnectWindow { get; set; }
KeepAliveData KeepAliveData { get; set; }
string MessageId { get; set; }
Expand Down
Expand Up @@ -66,7 +66,7 @@ public Task Start(IConnection connection, string connectionData, CancellationTok
throw new ArgumentNullException("connection");
}

var initializeHandler = new TransportInitializationHandler(connection.TransportConnectTimeout, disconnectToken);
var initializeHandler = new TransportInitializationHandler(connection.TotalTransportConnectTimeout, disconnectToken);

OnStart(connection, connectionData, disconnectToken, initializeHandler);

Expand Down
Expand Up @@ -75,7 +75,7 @@ public virtual Task Start(IConnection connection, string connectionData, Cancell
throw new ArgumentNullException("connection");
}

_initializeHandler = new TransportInitializationHandler(connection.TransportConnectTimeout, disconnectToken);
_initializeHandler = new TransportInitializationHandler(connection.TotalTransportConnectTimeout, disconnectToken);

// Tie into the OnFailure event so that we can stop the transport silently.
_initializeHandler.OnFailure += () =>
Expand Down
Expand Up @@ -231,6 +231,26 @@ public void WebSocketsTransportFailsIfOnConnectedThrows()
}
}

[Fact]
public void TransportConnectTimeoutDoesNotAddupOverNegotiateRequests()
{
using (ITestHost host = CreateHost(HostType.IISExpress))
{
host.Initialize();
var connection = CreateConnection(host, "/signalr");
connection.TransportConnectTimeout = TimeSpan.FromSeconds(5);

using (connection)
{
connection.Start().Wait();
var totalTransportConnectTimeout = ((Client.IConnection)connection).TotalTransportConnectTimeout;
connection.Stop();
connection.Start().Wait();
Assert.Equal(((Client.IConnection)connection).TotalTransportConnectTimeout, totalTransportConnectTimeout);
}
}
}

[Theory]
[InlineData("1337.0", HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData("1337.0", HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Fake)]
Expand Down

0 comments on commit 4e43c65

Please sign in to comment.