Permalink
Browse files

Merge branch 'release' into dev

  • Loading branch information...
2 parents 4d02bc5 + 34bdb41 commit cc5b002a5140e2d60184de42554a8737981c846c @davidfowl davidfowl committed Nov 22, 2012
@@ -2,6 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Client.Hubs;
+using Microsoft.AspNet.SignalR.FunctionalTests;
using Microsoft.AspNet.SignalR.FunctionalTests.Infrastructure;
using Microsoft.AspNet.SignalR.Hosting.Memory;
using Microsoft.AspNet.SignalR.Hubs;
@@ -36,7 +37,7 @@ public void EndToEndTest(HostType hostType, TransportType transportType)
hubConnection.Start(host.Transport).Wait();
- proxy.Invoke("Send", "hello").Wait();
+ proxy.InvokeWithTimeout("Send", "hello");
Assert.True(wh.WaitOne(TimeSpan.FromSeconds(10)));
@@ -65,7 +66,7 @@ public void HubNamesAreNotCaseSensitive(HostType hostType, TransportType transpo
hubConnection.Start(host.Transport).Wait();
- proxy.Invoke("Send", "hello").Wait();
+ proxy.InvokeWithTimeout("Send", "hello");
Assert.True(wh.WaitOne(TimeSpan.FromSeconds(10)));
}
@@ -84,7 +85,7 @@ public void UnableToCreateHubThrowsError(HostType hostType, TransportType transp
IHubProxy proxy = hubConnection.CreateHubProxy("MyHub2");
hubConnection.Start(host.Transport).Wait();
- Assert.Throws<MissingMethodException>(() => proxy.Invoke("Send", "hello").Wait());
+ Assert.Throws<MissingMethodException>(() => proxy.InvokeWithTimeout("Send", "hello"));
}
}
@@ -0,0 +1,61 @@
+using System;
+using Microsoft.AspNet.SignalR.Client.Hubs;
+using Xunit;
+
+namespace Microsoft.AspNet.SignalR.FunctionalTests
+{
+ public static class ClientAssertExtensions
+ {
+ private static readonly TimeSpan _defaultTimeout = TimeSpan.FromSeconds(10);
+
+ public static void SendWithTimeout(this Client.Connection connection, object value)
+ {
+ SendWithTimeout(connection, value, _defaultTimeout);
+ }
+
+ public static void SendWithTimeout(this Client.Connection connection, object value, TimeSpan timeout)
+ {
+ var task = connection.Send(value);
+
+ Assert.True(task.Wait(timeout), "Failed to get response from send");
+ }
+
+ public static void SendWithTimeout(this Client.Connection connection, string data)
+ {
+ SendWithTimeout(connection, data, _defaultTimeout);
+ }
+
+ public static void SendWithTimeout(this Client.Connection connection, string data, TimeSpan timeout)
+ {
+ var task = connection.Send(data);
+
+ Assert.True(task.Wait(timeout), "Failed to get response from send");
+ }
+
+ public static void InvokeWithTimeout(this IHubProxy proxy, string method, params object[] args)
+ {
+ InvokeWithTimeout(proxy, _defaultTimeout, method, args);
+ }
+
+ public static void InvokeWithTimeout(this IHubProxy proxy, TimeSpan timeout, string method, params object[] args)
+ {
+ var task = proxy.Invoke(method, args);
+
+ Assert.True(task.Wait(timeout), "Failed to get response from " + method);
+ }
+
+ public static T InvokeWithTimeout<T>(this IHubProxy proxy, string method, params object[] args)
+ {
+ return InvokeWithTimeout<T>(proxy, _defaultTimeout, method, args);
+ }
+
+ public static T InvokeWithTimeout<T>(this IHubProxy proxy, TimeSpan timeout, string method, params object[] args)
+ {
+ var task = proxy.Invoke<T>(method, args);
+
+ Assert.True(task.Wait(timeout), "Failed to get response from " + method);
+
+ return task.Result;
+ }
+ }
+}
@@ -98,6 +98,7 @@
<Compile Include="Connections\MyReconnect.cs" />
<Compile Include="Connections\MyRejoinGroupsConnection.cs" />
<Compile Include="Connections\MySendingConnection.cs" />
+ <Compile Include="Infrastructure\ClientAssertExtensions.cs" />
<Compile Include="Infrastructure\CountDownRange.cs" />
<Compile Include="Infrastructure\HostedTest.cs" />
<Compile Include="Infrastructure\HostType.cs" />
@@ -111,7 +111,7 @@ public void SendRaisesOnReceivedFromAllEvents(HostType hostType, TransportType t
};
connection.Start(host.Transport).Wait();
- connection.Send("").Wait();
+ connection.SendWithTimeout("");
Thread.Sleep(TimeSpan.FromSeconds(5));
@@ -150,7 +150,7 @@ public void SendCanBeCalledAfterStateChangedEvent(HostType hostType, TransportTy
{
if (stateChange.NewState == Client.ConnectionState.Connected)
{
- connection.Send("").Wait();
+ connection.SendWithTimeout("");
}
};
@@ -243,16 +243,16 @@ public void GroupsReceiveMessages(HostType hostType, TransportType transportType
connection.Start(host.Transport).Wait();
// Join the group
- connection.Send(new { type = 1, group = "test" }).Wait();
+ connection.SendWithTimeout(new { type = 1, group = "test" });
// Sent a message
- connection.Send(new { type = 3, group = "test", message = "hello to group test" }).Wait();
+ connection.SendWithTimeout(new { type = 3, group = "test", message = "hello to group test" });
// Leave the group
- connection.Send(new { type = 2, group = "test" }).Wait();
+ connection.SendWithTimeout(new { type = 2, group = "test" });
// Send a message
- connection.Send(new { type = 3, group = "test", message = "goodbye to group test" }).Wait();
+ connection.SendWithTimeout(new { type = 3, group = "test", message = "goodbye to group test" });
Thread.Sleep(TimeSpan.FromSeconds(5));
@@ -285,16 +285,16 @@ public void GroupsDontRejoinByDefault(HostType hostType, TransportType transport
connection.Start(host.Transport).Wait();
// Join the group
- connection.Send(new { type = 1, group = "test" }).Wait();
+ connection.SendWithTimeout(new { type = 1, group = "test" });
// Sent a message
- connection.Send(new { type = 3, group = "test", message = "hello to group test" }).Wait();
+ connection.SendWithTimeout(new { type = 3, group = "test", message = "hello to group test" });
// Force Reconnect
Thread.Sleep(TimeSpan.FromSeconds(5));
// Send a message
- connection.Send(new { type = 3, group = "test", message = "goodbye to group test" }).Wait();
+ connection.SendWithTimeout(new { type = 3, group = "test", message = "goodbye to group test" });
Thread.Sleep(TimeSpan.FromSeconds(5));
@@ -330,16 +330,16 @@ public void GroupsRejoinedWhenOnRejoiningGroupsOverridden(HostType hostType, Tra
connection.Start(host.Transport).Wait();
// Join the group
- connection.Send(new { type = 1, group = "test" }).Wait();
+ connection.SendWithTimeout(new { type = 1, group = "test" });
// Sent a message
- connection.Send(new { type = 3, group = "test", message = "hello to group test" }).Wait();
+ connection.SendWithTimeout(new { type = 3, group = "test", message = "hello to group test" });
// Force Reconnect
Thread.Sleep(TimeSpan.FromSeconds(5));
// Send a message
- connection.Send(new { type = 3, group = "test", message = "goodbye to group test" }).Wait();
+ connection.SendWithTimeout(new { type = 3, group = "test", message = "goodbye to group test" });
Thread.Sleep(TimeSpan.FromSeconds(5));
@@ -379,13 +379,13 @@ public void ClientGroupsSyncWithServerGroupsOnReconnect(HostType hostType, Trans
{
inGroupOnReconnect.Add(connection.Groups.Contains(typeof(MyRejoinGroupsConnection).FullName + ".test"));
- connection.Send(new { type = 3, group = "test", message = "Reconnected" }).Wait();
+ connection.SendWithTimeout(new { type = 3, group = "test", message = "Reconnected" });
};
connection.Start(host.Transport).Wait();
// Join the group
- connection.Send(new { type = 1, group = "test" }).Wait();
+ connection.SendWithTimeout(new { type = 1, group = "test" });
// Force reconnect
Thread.Sleep(TimeSpan.FromSeconds(10));
@@ -424,14 +424,14 @@ public void ClientGroupsSyncWithServerGroupsOnReconnectWhenNotRejoiningGroups(Ho
connection.Reconnected += () =>
{
- connection.Send(new { type = 1, group = "test2" }).Wait();
- connection.Send(new { type = 3, group = "test2", message = "Reconnected" }).Wait();
+ connection.SendWithTimeout(new { type = 1, group = "test2" });
+ connection.SendWithTimeout(new { type = 3, group = "test2", message = "Reconnected" });
};
connection.Start(host.Transport).Wait();
// Join the group
- connection.Send(new { type = 1, group = "test" }).Wait();
+ connection.SendWithTimeout(new { type = 1, group = "test" });
// Force reconnect
Thread.Sleep(TimeSpan.FromSeconds(5));
@@ -471,7 +471,7 @@ public void SendToAllButCaller(HostType hostType, TransportType transportType)
connection1.Start(host.Transport).Wait();
connection2.Start(host.Transport).Wait();
- connection1.Send("test").Wait();
+ connection1.SendWithTimeout("test");
Assert.False(wh1.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
Assert.True(wh2.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
Oops, something went wrong.

0 comments on commit cc5b002

Please sign in to comment.