public Task Do(IDictionary <string, object> stepParameters, IDictionary <string, object> pluginParameters, IList <IRpcClient> clients)
        {
            Log.Information($"Start connections...");

            // Get parameters
            stepParameters.TryGetTypedValue(SignalRConstants.ConcurrentConnection, out int concurrentConnection, Convert.ToInt32);
            stepParameters.TryGetTypedValue(SignalRConstants.Type, out string type, Convert.ToString);
            if (concurrentConnection < clients.Count)
            {
                concurrentConnection = clients.Count;
                var message = $"Concurrent connection {concurrentConnection} should NOT be less than the number of agents {clients.Count}, we force it to be {clients.Count}";
                Log.Warning(message);
            }

            var packages = clients.Select((client, i) =>
            {
                int currentConcurrentConnection = Util.SplitNumber(concurrentConnection, i, clients.Count);
                var data = new Dictionary <string, object>(stepParameters);
                data[SignalRConstants.ConcurrentConnection] = currentConcurrentConnection;
                return(new { Client = client, Data = data });
            });

            var results = from package in packages select package.Client.QueryAsync(package.Data);

            var task = Task.WhenAll(results);
            // we wait until the default timeout reached
            long expectedMilliseconds = SignalRConstants.MillisecondsToWait;

            if (SignalRUtils.FetchTotalConnectionFromContext(pluginParameters, type, out int totalConnections))
            {
                expectedMilliseconds = SignalRUtils.GetTimeoutPerConcurrentSpeed(totalConnections, concurrentConnection);
            }

            return(Util.TimeoutCheckedTask(task, expectedMilliseconds, nameof(StartConnection)));
        }
Beispiel #2
0
        protected Task Reconnect(
            IDictionary <string, object> stepParameters,
            IDictionary <string, object> pluginParameters,
            IList <IRpcClient> clients)
        {
            // Get parameters
            stepParameters.TryGetTypedValue(SignalRConstants.ConnectionTotal, out int connectionTotal, Convert.ToInt32);
            stepParameters.TryGetTypedValue(SignalRConstants.ConcurrentConnection, out int concurrentConnection, Convert.ToInt32);
            stepParameters.TryGetTypedValue(SignalRConstants.Type, out string type, Convert.ToString);
            // Prepare configuration for each clients
            var packages = clients.Select((client, i) =>
            {
                int currentConcurrentConnection = Util.SplitNumber(concurrentConnection, i, clients.Count);
                (int beg, int end) = Util.GetConnectionRange(connectionTotal, i, clients.Count);
                var data           = new Dictionary <string, object>(stepParameters);
                data[SignalRConstants.ConcurrentConnection] = currentConcurrentConnection > 0 ? currentConcurrentConnection : 1;
                return(new { Client = client, Data = data });
            });

            // Process on clients
            var results = from package in packages select package.Client.QueryAsync(package.Data);

            var  task = Task.WhenAll(results);
            long expectedMilliseconds = SignalRConstants.MillisecondsToWait;

            if (SignalRUtils.FetchTotalConnectionFromContext(pluginParameters, type, out int totalConnections))
            {
                expectedMilliseconds = SignalRUtils.GetTimeoutPerConcurrentSpeed(totalConnections, concurrentConnection);
            }

            return(Util.TimeoutCheckedTask(task, expectedMilliseconds, nameof(Reconnect)));
        }