public MeasuredHttpMessageHandler(AgentMetrics metrics) : base(new HttpClientHandler()) { response2xxMetric = metrics.GetOrCreate <Int64AgentMetric>("2xx"); response3xxMetric = metrics.GetOrCreate <Int64AgentMetric>("3xx"); response4xxMetric = metrics.GetOrCreate <Int64AgentMetric>("4xx"); response5xxMetric = metrics.GetOrCreate <Int64AgentMetric>("5xx"); }
public async Task ExecuteIterationsForUser(CancellationTokenSource cancellationTokenSource) { var finishAtUtc = DateTime.UtcNow + settings.SelectedProfile.RunFor; var userCountMetric = metrics.GetOrCreate <Int64AgentMetric>("Users"); exceptionCountMetric = metrics.GetOrCreate <Int64AgentMetric>("Exceptions"); await DelayStartIfRequired(); var scenario = scenarioFactory(); userCountMetric.Increment(); try { while (DateTime.UtcNow < finishAtUtc) { var iterationStartTicks = Stopwatch.GetTimestamp(); try { await scenario .ExecuteIteration() .ConfigureAwait(false); } catch (Exception exception) { HandleException(exception, cancellationTokenSource); } metrics.ReportProgressIfDue(finishAtUtc - DateTime.UtcNow); if (cancellationTokenSource.Token.IsCancellationRequested) { return; } await EnforceMinimumIterationTime(iterationStartTicks) .ConfigureAwait(false); } } finally { userCountMetric.Decrement(); } }