/// <summary> /// Creates a new test scenario /// </summary> /// <param name="totalUsers">The total number of simulated users that will be created during the test.</param> /// <param name="targetAddress">The URL of the remote host to test. Must be a valid absolute URI.</param> /// <param name="testDuration">The duration of the test, expressed in seconds. Must be between 30 and 300 seconds.</param> /// <param name="pauseDuration"> /// The duration of the pause between each step, expressed in seconds. Must be between 0 and 10 seconds. /// Defaults to 3 seconds. /// </param> /// <param name="userGrowthProgressionModel"> /// Describes the model that dictates how the number of concurrent users grows during the lifespan of the test. /// Defaults to linear. /// </param> internal Scenario(int totalUsers, string targetAddress, int testDuration, UserGrowthProgressionModel userGrowthProgressionModel, double timeout, int pauseDuration = 3) { bool throwsException = false; StringBuilder errorMessageBuilder = new StringBuilder(); if (totalUsers < 1) { throwsException = true; errorMessageBuilder.AppendLine("Total number of users must be greater than 0."); } else { this.Users = totalUsers; } if (!Uri.IsWellFormedUriString(targetAddress, UriKind.Absolute)) { throwsException |= true; errorMessageBuilder.AppendLine("The supplied target address is not valid."); } else { this.BaseAddress = new Uri(targetAddress); } if (testDuration < 30 || testDuration > 300) { throwsException |= true; errorMessageBuilder.AppendLine("Allowed test length is between 30 and 300 seconds."); } else { this.Duration = testDuration; } if (timeout < 0) { throwsException |= true; errorMessageBuilder.AppendLine("Time out must be greater than 0 milliseconds."); } else { this.Timeout = timeout; } if (pauseDuration < 0 || pauseDuration > 10) { throwsException |= true; errorMessageBuilder.AppendLine("Allowed pause length is between 0 and 10 seconds."); } else { this.PauseDuration = pauseDuration; } if (throwsException) { throw new ArgumentException("Error(s): " + errorMessageBuilder.ToString()); } this.UserGrowthProgressionModel = userGrowthProgressionModel; this.Steps = new List<HttpRequestMessage>(); }
public Engine(int totalUsers, string targetAddress, int testDuration, UserGrowthProgressionModel userGrowthProgressionModel, int pauseDuration, double timeout) { try { this.scenario = new Scenario(totalUsers, targetAddress, testDuration, userGrowthProgressionModel, timeout, pauseDuration); this.Factory = this.scenario.CreateStep; } catch (ArgumentException exception) { // TODO Log it throw; } // Init params this.testTimeElapsed = new Stopwatch(); this.executionResults = new List<HttpActionResult>(); this.progressUpdateFrequency = 5000; // Send an update out to the client every x seconds InitialiseTimers(); }