private bool DetectIfTestFailed(TestFileRunnerTaskInfo testFileTask) { bool failed = false; switch (testFileTask.CurrentTask?.Status) { case TaskStatus.Canceled: case TaskStatus.Faulted: failed = true; break; } return(failed); }
/// <summary> /// Shows the full information about a *single* test run - it doesn't have to be running, it could be complete. /// This includes the results of every test in the test file. /// </summary> public TaskDetails GetRunningTaskDetails(int taskId) { TestFileRunnerTaskInfo task = GetTestFileTaskInfo(taskId); TestFileRunner runner = task.Runner; return(new TaskDetails { TaskId = task.Id, Username = task.Username, Status = task.CurrentTask.Status.ToString(), Results = runner?.CurrentResults.ToList() ?? new List <TestResult>(), CurrentIndex = runner?.TestsRun ?? 0, TotalTests = runner?.TotalTests ?? 0, Errors = task.Errors }); }
private static IEnumerable <LightweightResult> GenerateTestResults(TestFileRunnerTaskInfo runnerInfo) { return(runnerInfo?.TestFileResults?.TestResults?.Select(lightResult => new LightweightResult { Success = lightResult.Success, Message = lightResult.Message, ExceptionMessage = lightResult.ExceptionMessage, AssertionsSuccess = lightResult.AssertionsSuccess, ScriptCompilationSuccess = lightResult.ScriptCompilationSuccess, ResponseTime = lightResult.ResponseTime, ResponseCodeSuccess = lightResult.ResponseCodeSuccess, ActualUrl = lightResult.ActualUrl, TestUrl = lightResult.Test?.Url, TestDescription = lightResult.Test?.Description }) ?? new LightweightResult[0]); }
public TestFileRunResult Create(TestFileRunnerTaskInfo runnerInfo, bool timedOut, TimeSpan timeTaken) { TestFileRunResult result; if (timedOut) { // Error result = new TestFileRunResult { Finished = false, TimeTaken = timeTaken, ErrorMessage = "The runner timed out." }; } else { if (!string.IsNullOrEmpty(runnerInfo.Errors)) { result = new TestFileRunResult { Finished = false, TimeTaken = timeTaken, ErrorMessage = runnerInfo.Errors }; } else { int failCount = runnerInfo.TestFileResults?.TestResults?.Count(x => !x.Success) ?? 0; result = new TestFileRunResult { ResultId = runnerInfo.TestFileResults?.Id, HasFailedTests = (failCount > 0), ErrorMessage = string.Empty, Finished = DetectIfTestHasFinished(runnerInfo), TestRunFailed = DetectIfTestFailed(runnerInfo), TimeTaken = GetTimeTaken(runnerInfo, timeTaken), TestResults = GenerateTestResults(runnerInfo) }; } } return(result); }
/// <summary> /// Starts the test file run. /// </summary> public async Task StartSessionAsync(TestFileRunnerTaskInfo item) { try { string filename = item.Request.Filename; TestFile testFile = _assembler.AssembleTestFile(filename, item.Request.Environment); TestFileRunner runner = _testFileRunnerFactory.Create(); item.Runner = runner; item.TestFileResults = await runner.RunAsync(testFile, item.Request.Environment, item.Request.Username); } catch (Exception e) { item.Errors = e.ToString(); } }
public BatchStatus GetBatchStatus(int batchId) { string key = $"{KeyPrefix}{batchId}"; if (!_objectCache.Contains(key)) { throw new KeyNotFoundException($"Unknown batch id: {batchId}"); } var batchInfo = (List <int>)_objectCache[key]; var testFilesState = new List <TestFileRunResult>(batchInfo.Count); var failedTests = new List <int>(); foreach (int taskId in batchInfo) { TestFileRunnerTaskInfo taskInfo = _testFileQueue.GetTestFileTaskInfo(taskId); TestFileRunResult testFileRunResult = _testFileResultFactory.Create(taskInfo, false, TimeSpan.Zero); testFilesState.Add(testFileRunResult); if (testFileRunResult.TestRunFailed) { failedTests.Add(taskId); } } bool batchFinished = testFilesState.TrueForAll(x => x.Finished); IEnumerable <Guid> testFilesResultIds = testFilesState .Where(x => x.ResultId.HasValue) .Select(x => x.ResultId.Value); return(new BatchStatus { BatchId = batchId, TestFilesResultIds = testFilesResultIds, BatchFinished = batchFinished, HasFailedTests = testFilesState.Any(x => x.TestRunFailed) || batchFinished && testFilesState.Any(x => x.HasFailedTests), TestFilesRunning = testFilesState.Count(x => !x.Finished), TestFilesFinished = testFilesState.Count(x => x.Finished), TestFilesWithFailedTests = testFilesState.Where(x => x.HasFailedTests && x.ResultId.HasValue).Select(x => x.ResultId.Value), TestFilesFailed = failedTests.Count, FailedTasks = failedTests, }); }
/// <summary> /// Adds a request to run a test file to the queue of tasks to run. /// </summary> public int Add(TaskRequest item) { int taskId = Interlocked.Increment(ref _lastTaskId); var cancelTokenSource = new CancellationTokenSource(); var taskInfo = new TestFileRunnerTaskInfo(taskId) { Request = item, StartTime = DateTime.UtcNow, Username = item.Username }; Task childTask = StartSessionAsync(taskInfo); taskInfo.CancelTokenSource = cancelTokenSource; taskInfo.CurrentTask = childTask; _currentTasks.TryAdd(taskId, taskInfo); return(taskId); }
private bool DetectIfTestHasFinished(TestFileRunnerTaskInfo testFileTask) { return(testFileTask.CurrentTask?.Status == TaskStatus.RanToCompletion); }
private TimeSpan GetTimeTaken(TestFileRunnerTaskInfo testFile, TimeSpan timeTaken) { return(timeTaken == TimeSpan.Zero && testFile.TestFileResults != null ? testFile.TestFileResults.TotalRunTime : timeTaken); }