private async Task RampUpAsync(TestRunInfo testRunInfo) { // Handle ramp up if defined if (testRunInfo.RampUpTimeSeconds > 4 && !_cancellationTokenSource.IsCancellationRequested) { Tracer.TraceInfo($"Ramping up starts."); DateTime startTime = DateTime.Now; DateTime endTime = startTime + TimeSpan.FromSeconds(testRunInfo.RampUpTimeSeconds); int numberIntervals = Math.Min(testRunInfo.RampUpTimeSeconds / 5, 6); TimeSpan intervalLength = (endTime - startTime) / numberIntervals; double intervalRpsDelta = ((double)testRunInfo.TargetRPS) / ((double)numberIntervals); for (int i = 0; i < numberIntervals && !_cancellationTokenSource.IsCancellationRequested; i++) { var apiInfo = _mixInfo.ApiMix[i % _mixInfo.ApiMix.Count]; long intervalRps = (long)Math.Round((i + 1) * intervalRpsDelta); Tracer.TraceInfo($"Ramping up. RPS = {intervalRps}"); AsyncFor myRampUpFor = new AsyncFor(intervalRps, GetResourceDescription(apiInfo, _mixInfo), GetTestDescription(apiInfo), testRunInfo.MeasureServerSideTime); myRampUpFor.PerSecondMetricsAvailable += new ConsoleMetricsHandler().MetricsAvailableHandler; _asyncForInstances.Add(myRampUpFor); try { await myRampUpFor.ForAsync( intervalLength, testRunInfo.SimultaneousConnections, new MaaServiceApiCaller(apiInfo, _mixInfo.ProviderMix, testRunInfo.EnclaveInfoFile, testRunInfo.ForceReconnects).CallApi, _cancellationTokenSource.Token); } catch (TaskCanceledException) { // Ignore task cancelled if we requested cancellation via ctrl-c if (_cancellationTokenSource.IsCancellationRequested) { Tracer.TraceInfo(($"Organized shutdown in progress. All asyncfor instances have gracefully shutdown.")); } else { throw; } } } Tracer.TraceInfo($"Ramping up complete."); } }