예제 #1
0
        private bool DetectIfTestFailed(TestFileRunnerTaskInfo testFileTask)
        {
            bool failed = false;

            switch (testFileTask.CurrentTask?.Status)
            {
            case TaskStatus.Canceled:
            case TaskStatus.Faulted:
                failed = true;
                break;
            }

            return(failed);
        }
예제 #2
0
        /// <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
            });
        }
예제 #3
0
 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]);
 }
예제 #4
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);
        }
예제 #5
0
        /// <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();
            }
        }
예제 #6
0
        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,
            });
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
 private bool DetectIfTestHasFinished(TestFileRunnerTaskInfo testFileTask)
 {
     return(testFileTask.CurrentTask?.Status == TaskStatus.RanToCompletion);
 }
예제 #9
0
 private TimeSpan GetTimeTaken(TestFileRunnerTaskInfo testFile, TimeSpan timeTaken)
 {
     return(timeTaken == TimeSpan.Zero && testFile.TestFileResults != null ? testFile.TestFileResults.TotalRunTime : timeTaken);
 }