asp.net-mvc – 加载测试SignalR集线器应用程序的最佳方法是什么?

我想知道一些用于测试基于SignalR集线器的应用程序的不同方法

解决方法

@ElHaix从我自己测试中看到的方法,你的方法不是创建一个新的连接,而是重用现有的连接。当您循环查看profileID的集合时,您应该看到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);
        }

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....