/// <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; }
public IterationResult(TestContext testContext) { ThreadId = testContext.ThreadId; GlobalIterationId = testContext.GlobalIterationId; ThreadIterationId = testContext.ThreadIterationId; UserData = testContext.UserData; IterationStarted = testContext.IterationStarted; IterationFinished = testContext.IterationFinished; Checkpoints = testContext.LoggedCheckpoints.Select(c => c).Cast<ICheckpoint>().ToArray(); }
public TestExecutorThread(ILoadTestScenario loadTestScenario, ITimer timer, int threadId, object initialUserData) { if (loadTestScenario == null) throw new ArgumentNullException(nameof(loadTestScenario)); if (timer == null) throw new ArgumentNullException(nameof(timer)); _testContext = new TestContext(threadId, timer, initialUserData); _loadTestScenario = loadTestScenario; _handlerThread = new Thread(ExecuteScenarioThreadFunction); }
private static bool ExecuteWithExceptionHandling(Action action, TestContext testContext) { bool result = false; try { action.Invoke(); result = true; } catch (Exception ex) { testContext.SetError(ex); } return result; }