/// <summary> /// Validates ILoadTest scenario correctness by executing single test iteration /// from ScenarioSetup to ScenarioTearDown on the same thread. /// Exceptions are not handled on purpose to ease problem identification while developing. /// </summary> /// <param name="loadTestScenario">ILoadTestScenario object</param> /// <param name="threadId">TheardId to set in TestContext</param> /// <param name="threadIterationId">ThreadIterationId to set in TestContext</param> /// <param name="globalIterationId">GlobalIterationId to set in TestContext</param> /// <returns>Raw result from single iteration</returns> public static IterationResult Validate(ILoadTestScenario loadTestScenario, int threadId = 0, int threadIterationId = 0, int globalIterationId = 0) { ExecutionTimer timer = new ExecutionTimer(); TestContext testContext = new TestContext(threadId, timer); testContext.Reset(-1, -1); loadTestScenario.ScenarioSetup(testContext); testContext.Reset(threadIterationId, globalIterationId); testContext.Checkpoint(Checkpoint.IterationSetupCheckpointName); loadTestScenario.IterationSetup(testContext); testContext.Checkpoint(Checkpoint.IterationStartCheckpointName); testContext.Start(); loadTestScenario.ExecuteScenario(testContext); testContext.Stop(); testContext.Checkpoint(Checkpoint.IterationEndCheckpointName); testContext.Checkpoint(Checkpoint.IterationTearDownCheckpointName); loadTestScenario.IterationTearDown(testContext); IterationResult result = new IterationResult(testContext); testContext.Reset(-1, -1); loadTestScenario.ScenarioTearDown(testContext); return result; }
/// <summary> /// Validates ILoadTest scenario correctness by executing single test iteration /// from ScenarioSetup to ScenarioTearDown on the same thread. /// Exceptions are not handled on purpose to ease problem identification while developing. /// </summary> /// <param name="loadTestScenario">ILoadTestScenario object</param> /// <param name="threadId">TheardId to set in TestContext</param> /// <param name="threadIterationId">ThreadIterationId to set in TestContext</param> /// <param name="globalIterationId">GlobalIterationId to set in TestContext</param> /// <returns>Raw result from single iteration</returns> public static IterationResult Validate(ILoadTestScenario loadTestScenario, int threadId = 0, int threadIterationId = 0, int globalIterationId = 0) { ExecutionTimer timer = new ExecutionTimer(); TestContext testContext = new TestContext(threadId, timer); testContext.Reset(-1, -1); loadTestScenario.ScenarioSetup(testContext); testContext.Reset(threadIterationId, globalIterationId); testContext.Checkpoint(Checkpoint.IterationSetupCheckpointName); loadTestScenario.IterationSetup(testContext); testContext.Checkpoint(Checkpoint.IterationStartCheckpointName); testContext.Start(); loadTestScenario.ExecuteScenario(testContext); testContext.Stop(); testContext.Checkpoint(Checkpoint.IterationEndCheckpointName); testContext.Checkpoint(Checkpoint.IterationTearDownCheckpointName); loadTestScenario.IterationTearDown(testContext); IterationResult result = new IterationResult(testContext); testContext.Reset(-1, -1); loadTestScenario.ScenarioTearDown(testContext); return(result); }
private void ExecuteScenarioThreadFunction() { try { int threadIterationId = 0; ExecuteScenarioSetup(); while (_stopQueued == false || _executeIterationQueued) { if (_executeIterationQueued) { _testContext.Reset(threadIterationId++, _queuedIterationId); _testContext.Checkpoint(Checkpoint.IterationSetupCheckpointName); bool setupSuccess = ExecuteWithExceptionHandling(() => _loadTestScenario.IterationSetup(_testContext), _testContext); if (setupSuccess) { _testContext.Checkpoint(Checkpoint.IterationStartCheckpointName); _testContext.Start(); bool iterationSuccess = ExecuteWithExceptionHandling(() => _loadTestScenario.ExecuteScenario(_testContext), _testContext); _testContext.Stop(); if (iterationSuccess) { _testContext.Checkpoint(Checkpoint.IterationEndCheckpointName); } } else { _testContext.Start(); _testContext.Stop(); } _testContext.Checkpoint(Checkpoint.IterationTearDownCheckpointName); ExecuteWithExceptionHandling(() => _loadTestScenario.IterationTearDown(_testContext), _testContext); _executeIterationQueued = false; OnScenarioIterationFinished(); } else { Thread.Sleep(1); } } _testContext.Reset(-1, -1); _loadTestScenario.ScenarioTearDown(_testContext); } catch (Exception ex) { if (ex.GetType() != typeof(ThreadAbortException)) { OnThreadFailed(ex); } } }