private bool validateScenario(LrScenario scenario, ref string errorReason) { //validate that scenario has SLA if (!scenario.DoesScenarioHaveSLAConfiguration()) { errorReason = string.Format(Resources.LrScenarioValidationFailNoSLA, scenario.FileName); return(false); } //validate that all scripts are available. if (!scenario.AreScriptsAccessible(out errorReason)) { //error message in errorReason return(false); } //validate LGs: if (scenario.Hosts.Count == 0) { errorReason = string.Format(Resources.LrScenarioValidationFailNoLGs, scenario.FileName); return(false); } //connect to all active load generators == hosts: int ret; foreach (LrHost lg in scenario.Hosts) { //handle only active hosts if (lg.IsUsed()) { //connect to the host ret = lg.Connect(); if (ret != 0) { errorReason = string.Format(Resources.LrScenarioValidationCannotConnectLG, lg.Name); return(false); } //sync with the host ret = lg.Sync(60); if (ret <= 0) { errorReason = string.Format(Resources.LrScenarioValidationCannotSyncLG, lg.Name);; return(false); } //if host is not ready after sync, invalidate the test if (lg.Status != LrHostStatus.lrHostReady) { errorReason = string.Format(Resources.LrScenarioValidationLGNotReady, lg.Name); return(false); } //if we got this far, lg is connected and ready to go ConsoleWriter.WriteLine(string.Format(Resources.LrScenarioValidationLGConnected, lg.Name)); } } return(true); }
public void LogTransactionDetails(LrScenario scenario) { string transactionDetails; scenario.GetTransactionStatisticsDetails(out transactionDetails); ConsoleWriter.WriteLine("Transaction details: " + transactionDetails); }
private void LogScenarioDuration(LrScenario scenario) { int scenarioDuration = scenario.ScenarioDuration; TimeSpan time = TimeSpan.FromSeconds(scenarioDuration); string convertedTime = time.ToString(@"dd\:hh\:mm\:ss"); ConsoleWriter.WriteLine("Elapsed Time (D:H:M:S): " + convertedTime); }
private void LogTransactionStatistics(LrScenario scenario) { int passed = 0, failed = 0; double hitsPerSecond = 0; scenario.GetTransactionStatistics(ref passed, ref failed, ref hitsPerSecond); ConsoleWriter.WriteLine("Passed transactions: " + passed); ConsoleWriter.WriteLine("Failed transactions: " + failed); ConsoleWriter.WriteLine("Hits per second: " + Math.Round(hitsPerSecond, 2)); }
private void LogVuserStates(LrScenario scenario) { StringBuilder headerBuilder = new StringBuilder(), bodyBuilder = new StringBuilder(); foreach (var vuserState in Enum.GetValues(typeof(VUSERS_STATE))) { headerBuilder.Append(string.Format("{0, -10}", vuserState.ToString())); } foreach (var vuserState in Enum.GetValues(typeof(VUSERS_STATE))) { bodyBuilder.Append(string.Format("{0, -10}", scenario.GetVusersCount((int)vuserState))); } ConsoleWriter.WriteLine(headerBuilder.ToString()); ConsoleWriter.WriteLine(bodyBuilder.ToString()); }
public void LogSummaryData(LrScenario scenario) { if (m_logVusersStates || m_logErrorCount || m_logTransactionStatistics) { LogScenarioDuration(scenario); if (m_logVusersStates) { LogVuserStates(scenario); } if (m_logErrorCount) { LogErrorCount(scenario); } if (m_logTransactionStatistics) { LogTransactionStatistics(scenario); } } }
private void LogDataDuringScenarioExecution() { ThreadStart summaryDataLoggingThread = () => { try { LrScenario currentScenario = _engine.Scenario; while (!_scenarioEnded) { _summaryDataLogger.LogSummaryData(currentScenario); Thread.Sleep(_summaryDataLogger.GetPollingInterval()); } } catch (Exception e) { ConsoleWriter.WriteErrLine(string.Format(Resources.LrSummaryDataLoggingError, e.Message)); return; } }; Thread t = new Thread(summaryDataLoggingThread); t.Start(); }
private void LogErrorCount(LrScenario scenario) { int errorsCount = scenario.GetErrorsCount(""); ConsoleWriter.WriteLine("Error count: " + errorsCount); }
private bool runScenario(string scenario, ref string errorReason, RunCancelledDelegate runCancelled) { cleanENV(); ConsoleWriter.WriteLine(string.Format(Resources.LrInitScenario, scenario)); //start controller _engine = new LrEngine(); if (_engine == null) { errorReason = string.Format(Resources.LrFailToOpenController, scenario); return(false); } //try to register the end scenario event: _scenarioEndedEvent = false; try { _engine.Events.ScenarioEvents.OnScenarioEnded += ScenarioEvents_OnScenarioEnded; _scenarioEndedEvent = true; } catch (Exception e) { ConsoleWriter.WriteException(Resources.LrFailToRegisterEndScenarioEvent, e); _scenarioEndedEvent = false; } if (_displayController == true) { _engine.ShowMainWindow(1); } else { _engine.ShowMainWindow(0); } //pointer to the scenario object: LrScenario currentScenario = _engine.Scenario; //try to open the scenario and validate the scenario and connect to load generators if (openScenario(scenario, ref errorReason) && validateScenario(currentScenario, ref errorReason)) { //apply rts to scripts foreach (ScriptRTSModel scriptRTS in _scriptRTSSet) { try { LrScripts currentScripts = currentScenario.Scripts; LrScript currentScript = currentScripts.Item[scriptRTS.GetScriptName()]; string runtimeSettings = "", actionLogic = ""; currentScript.GetScriptRunTimeSettings(ref runtimeSettings, ref actionLogic); RTSHelper rtsHelper = new RTSHelper(runtimeSettings, RTSHelper.COMMAND_ARGUMENTS, scriptRTS.GetKeyValuePairs()); string updatedRuntimeSettings = rtsHelper.GetUpdatedIniFileText(); currentScript.SetScriptRunTimeSettings(updatedRuntimeSettings, actionLogic); } catch (Exception e) { errorReason = string.Format(Resources.LrRTSError, scriptRTS.GetScriptName(), e.Message); return(false); } } //set the result dir: ConsoleWriter.WriteLine("setting scenario result folder to " + Path.Combine(_resultsFolder, LRR_FOLDER)); currentScenario.ResultDir = Path.Combine(_resultsFolder, LRR_FOLDER); ConsoleWriter.WriteLine("scenario result folder: " + currentScenario.ResultDir); //check if canceled or timedOut: if (_runCancelled()) { errorReason = Resources.GeneralTimedOut; return(false); } _scenarioEnded = false; ConsoleWriter.WriteLine(Resources.LrStartScenario); int ret = currentScenario.Start(); if (!currentScenario.ResultDir.Equals(Path.Combine(_resultsFolder, LRR_FOLDER))) { ConsoleWriter.WriteLine("controller failed to write to " + Path.Combine(_resultsFolder, LRR_FOLDER) + " setting result folder to " + currentScenario.ResultDir); _controller_result_dir = new DirectoryInfo(currentScenario.ResultDir).Name; ConsoleWriter.WriteLine("controller reult dir: " + _controller_result_dir); } if (ret != 0) { errorReason = string.Format(Resources.LrStartScenarioFail, scenario, ret); return(false); } //per scenario timeout stopwatch _stopWatch = Stopwatch.StartNew(); //wait for scenario to end: if (!waitForScenario(ref errorReason)) { //something went wrong during scenario execution, error reason set in errorReason string return(false); } else {//scenario has ended Console.WriteLine(string.Format(Resources.LrScenarioEnded, scenario, _stopWatch.Elapsed.Hours, _stopWatch.Elapsed.Minutes, _stopWatch.Elapsed.Seconds)); //collate results collateResults(); } } else { return(false); } return(true); }
private bool runScenario(string scenario, ref string errorReason, RunCancelledDelegate runCancelled) { cleanENV(); ConsoleWriter.WriteLine(string.Format(Resources.LrInitScenario, scenario)); //start controller _engine = new LrEngine(); if (_engine == null) { errorReason = string.Format(Resources.LrFailToOpenController, scenario); return(false); } //try to register the end scenario event: _scenarioEndedEvent = false; try { _engine.Events.ScenarioEvents.OnScenarioEnded += ScenarioEvents_OnScenarioEnded; _scenarioEndedEvent = true; } catch (Exception e) { ConsoleWriter.WriteException(Resources.LrFailToRegisterEndScenarioEvent, e); _scenarioEndedEvent = false; } _engine.ShowMainWindow(0); #if DEBUG _engine.ShowMainWindow(1); #endif //pointer to the scenario object: LrScenario currentScenario = _engine.Scenario; //try to open the scenario and validate the scenario and connect to load generators if (openScenario(scenario, ref errorReason) && validateScenario(currentScenario, ref errorReason)) { //set the result dir: ConsoleWriter.WriteLine("setting scenario result folder to " + Path.Combine(_resultsFolder, LRR_FOLDER)); currentScenario.ResultDir = Path.Combine(_resultsFolder, LRR_FOLDER); ConsoleWriter.WriteLine("scenario result folder: " + currentScenario.ResultDir); //check if canceled or timedOut: if (_runCancelled()) { errorReason = Resources.GeneralTimedOut; return(false); } _scenarioEnded = false; ConsoleWriter.WriteLine(Resources.LrStartScenario); int ret = currentScenario.Start(); if (!currentScenario.ResultDir.Equals(Path.Combine(_resultsFolder, LRR_FOLDER))) { ConsoleWriter.WriteLine("controller failed to write to " + Path.Combine(_resultsFolder, LRR_FOLDER) + " setting result folder to " + currentScenario.ResultDir); _controller_result_dir = new DirectoryInfo(currentScenario.ResultDir).Name; ConsoleWriter.WriteLine("controller reult dir: " + _controller_result_dir); } if (ret != 0) { errorReason = string.Format(Resources.LrStartScenarioFail, scenario, ret); return(false); } //per scenario timeout stopwatch _stopWatch = Stopwatch.StartNew(); //wait for scenario to end: if (!waitForScenario(ref errorReason)) { //something went wrong during scenario execution, error reason set in errorReason string return(false); } else {//scenario has ended Console.WriteLine(string.Format(Resources.LrScenarioEnded, scenario, _stopWatch.Elapsed.Hours, _stopWatch.Elapsed.Minutes, _stopWatch.Elapsed.Seconds)); //collate results collateResults(); } } else { return(false); } return(true); }
private bool validateScenario(LrScenario scenario, ref string errorReason) { //validate that scenario has SLA if (!scenario.DoesScenarioHaveSLAConfiguration()) { errorReason = string.Format(Resources.LrScenarioValidationFailNoSLA, scenario.FileName); return false; } //validate that all scripts are available. if (!scenario.AreScriptsAccessible(out errorReason)) { //error message in errorReason return false; } //validate that scenario has time limited schedule: if (!scenario.DoesScenarioHaveLimitedSchedule(out errorReason)) { //error message in errorReason return false; } //validate LGs: if (scenario.Hosts.Count == 0) { errorReason = string.Format(Resources.LrScenarioValidationFailNoLGs, scenario.FileName); return false; } //connect to all active load generators == hosts: int ret; foreach (LrHost lg in scenario.Hosts) { //handle only active hosts if (lg.IsUsed()) { //connect to the host ret = lg.Connect(); if (ret != 0) { errorReason = string.Format(Resources.LrScenarioValidationCannotConnectLG, lg.Name); return false; } //sync with the host ret = lg.Sync(60); if (ret <= 0) { errorReason = string.Format(Resources.LrScenarioValidationCannotSyncLG, lg.Name); ; return false; } //if host is not ready after sync, invalidate the test if (lg.Status != LrHostStatus.lrHostReady) { errorReason = string.Format(Resources.LrScenarioValidationLGNotReady, lg.Name); return false; } //if we got this far, lg is connected and ready to go ConsoleWriter.WriteLine(string.Format(Resources.LrScenarioValidationLGConnected, lg.Name)); } } return true; }