我想了解一些测试基于SignalR hubs的应用程序所使用的不同方法。
我想了解一些测试基于SignalR hubs的应用程序所使用的不同方法。
简而言之,如果使用Hubs,则使用.Net客户端就足够了。
在我的情况下,我有一个新闻订阅Hub,根据用户的配置文件ID提供客户端特定数据。在我的测试案例中,我加载了一堆配置文件ID(本例中为6000),调用名为JoinNewsfeed()的hub方法,同时提供客户端特定的连接ID和配置文件ID。每100毫秒建立一个新的连接。
[TestMethod]
public void TestJoinNewsfeedHub()
{
int successfulConnections = 0;
// get profile ID's
memberService = new MemberServiceClient();
List<int> profileIDs = memberService.GetProfileIDs(6000).ToList<int>();
HubConnection hubConnection = new HubConnection(HUB_URL);
IHubProxy newsfeedHub = hubConnection.CreateProxy("NewsfeedHub");
foreach (int profileID in profileIDs)
{
hubConnection.Start().Wait();
//hubConnection = EstablishHubConnection();
newsfeedHub.Invoke<string>("JoinNewsfeed", hubConnection.ConnectionId, profileID).ContinueWith(task2 =>
{
if (task2.IsFaulted)
{
System.Diagnostics.Debug.Write(String.Format("An error occurred during the method call {0}", task2.Exception.GetBaseException()));
}
else
{
successfulConnections++;
System.Diagnostics.Debug.Write(String.Format("Successfully called MethodOnServer: {0}", successfulConnections));
}
});
Thread.Sleep(100);
}
Assert.IsNotNull(newsfeedHub);
}
这里列出的性能指标在服务器上起到了作用。为确保客户端已连接并且在服务器上成功完成了填充客户端对象的过程,我有一个服务器端方法,它调用一个客户端函数,并提供从已连接客户端集合中派生的连接客户端数量和列表。
@ElHaix,根据我自己的测试结果,你的方法并没有创建新的连接,而是重用了现有的连接。当你循环遍历profileIDs集合时,你应该会发现hubConnection.ConnectionID保持不变。如果想要创建一个新的连接,你需要在foreach循环内部创建一个HubConnection实例。
int successfulConnections = 0;
const int loopId = 10;
Console.WriteLine("Starting...");
for (int i = 1; i <= loopId; i++)
{
Console.WriteLine("loop " + i);
var hubConnection = new HubConnection(HUB_URL);
IHubProxy chatHub = hubConnection.CreateProxy(HUB_NAME);
Console.WriteLine("Starting connection");
hubConnection.Start().Wait();
Console.WriteLine("Connection started: " + hubConnection.ConnectionId);
chatHub.Invoke("Register", "testroom").ContinueWith(task2 =>
{
if (task2.IsFaulted)
{
Console.WriteLine(String.Format("An error occurred during the method call {0}", task2.Exception.GetBaseException()));
}
else
{
Console.WriteLine("Connected: " + hubConnection.ConnectionId);
successfulConnections++;
}
});
Thread.Sleep(1000);
}
使用Gatling工具编写自己的脚本以创建虚拟用户(多线程),并使用Java SignalR客户端。如果您想知道如何将自定义的Java或Scala脚本附加到Gatling虚拟用户,请在评论中说明。如果需要进行SignalR性能测试的测试计划,请告诉我,因为这是进行测试的关键。