Ejemplo n.º 1
0
        public static LoadRunnerUi BuildUi(this IStrategyBuilder builder, IValidator validator = null)
        {
            if (!(builder is IAggregatorFeature))
            {
                throw new ArgumentException("Strategy builder must support IAggrregatorFeature");
            }

            LoadRunnerUi       ui           = new LoadRunnerUi();
            IAggregatorFeature localBuilder = (IAggregatorFeature)builder.ShallowCopy();

            localBuilder.AddAggregator(ui);

            ui.Setup(localBuilder.BuildStrategy(), validator);

            return(ui);
        }
Ejemplo n.º 2
0
        public static void Run()
        {
            // LoadRunnerParameters initializes defaults shown below
            LoadRunnerParameters loadRunnerParameters = new LoadRunnerParameters
            {
                Limits = new ExecutionLimits
                {
                    // Maximum LoadTest duration threshold, after which test is stopped
                    MaxDuration = TimeSpan.FromSeconds(30),

                    // Maximum executed iterations count threshold, after which test is stopped
                    MaxIterationsCount = Int32.MaxValue,

                    // Once LoadTest execution finishes because of [maxDuration] or [maxIterationsCount] limit
                    // coordinating thread will wait [FinishTimeout] amount of time before
                    // terminating them with Thread.Abort()
                    //
                    // Aborted threads won't get the chance to call IterationTearDown() or ScenarioTearDown()
                    // neither it will broadcast TestContextResultReceived() to aggregators with the state as it is after abort.
                    FinishTimeout = TimeSpan.FromSeconds(60)
                },

                // [ISpeedStrategy] defines maximum allowed load by dampening executed Iterations per second count
                // * Other existing version of [ISpeedStrategy]
                //    - IncremantalSpeed(initialRequestsPerSec: 1.0, increasePeriod: TimeSpan.FromSeconds(10), increaseStep: 3.0)
                SpeedStrategy = new FixedSpeed(maxIterationsPerSec: Double.MaxValue),

                //[IThreadingStrategy] defines allowed worker thread count
                // * SemiAutoThreading initializes [minThreadCount] at begining
                // It will be increased if not enough threads are available to reach [ISpeedStrategy] limits
                ThreadingStrategy = new IncrementalThreadCount(15, TimeSpan.FromSeconds(10), 15)
            };

            // Initialize aggregator
            string[] ignoredCheckpoints =
            {
                Checkpoint.IterationSetupCheckpointName,
                Checkpoint.IterationStartCheckpointName,
                Checkpoint.IterationTearDownCheckpointName
            };

            HistogramAggregator histogramAggregator = new HistogramAggregator()
                                                      .Add(new TimeDimension(TimeSpan.FromSeconds(10)))
                                                      .Add(new MinDurationMetric(ignoredCheckpoints))
                                                      .Add(new AvgDurationMetric(ignoredCheckpoints))
                                                      .Add(new MaxDurationMetric(ignoredCheckpoints))
                                                      .Add(new PercentileMetric(new[] { 0.5, 0.8, 0.9, 0.95, 0.99 }, ignoredCheckpoints))
                                                      .Add(new CountMetric(ignoredCheckpoints))
                                                      .Add(new ErrorCountMetric())
                                                      .Add(new FuncMetric <int>("Created Threads", 0, (i, result) => result.CreatedThreads))
                                                      .Alias($"Min: {Checkpoint.IterationEndCheckpointName}", "Min (ms)")
                                                      .Alias($"Avg: {Checkpoint.IterationEndCheckpointName}", "Avg (ms)")
                                                      .Alias($"Max: {Checkpoint.IterationEndCheckpointName}", "Max (ms)")
                                                      .Alias($"50%: {Checkpoint.IterationEndCheckpointName}", "50% (ms)")
                                                      .Alias($"80%: {Checkpoint.IterationEndCheckpointName}", "80% (ms)")
                                                      .Alias($"90%: {Checkpoint.IterationEndCheckpointName}", "90% (ms)")
                                                      .Alias($"95%: {Checkpoint.IterationEndCheckpointName}", "95% (ms)")
                                                      .Alias($"99%: {Checkpoint.IterationEndCheckpointName}", "99% (ms)")
                                                      .Alias($"Count: {Checkpoint.IterationEndCheckpointName}", "Success: Count")
                                                      .Alias($"Errors: {Checkpoint.IterationSetupCheckpointName}", "Errors: Setup")
                                                      .Alias($"Errors: {Checkpoint.IterationStartCheckpointName}", "Errors: Iteration")
                                                      .Alias($"Errors: {Checkpoint.IterationTearDownCheckpointName}", "Errors: Teardown");

            JsonStreamAggregator _jsonStreamAggregator = new JsonStreamAggregator(() => DateTime.Now.ToString("HH_mm_ss__ffff") + ".json");

            //TotalsResultsAggregator resultsAggregator = new TotalsResultsAggregator();

            // Initializing LoadTest Client
            //LoadRunnerEngine loadRunner = LoadRunnerEngine.Create<TestScenario>(loadRunnerParameters, histogramAggregator, _jsonStreamAggregator);

            LoadRunnerUi loadRunnerUi = LoadRunnerUi.Create <TestScenario>(loadRunnerParameters, histogramAggregator, _jsonStreamAggregator);

            Application.Run(loadRunnerUi);
            return;
            // Run test (blocking call)
            //loadRunner.Run();

            //loadRunner.RunAsync();
            //Console.WriteLine("Async started");
            //loadRunner.Wait();

            //object defaultResults = histogramAggregator.BuildResultsObjects();
            //Console.WriteLine(JsonConvert.SerializeObject(defaultResults, Formatting.Indented));

            //Console.ReadKey();
        }