Пример #1
0
        public TestFileRunResult RunTestFile(string filename, string environment, string username)
        {
            DateTime startTime = DateTime.UtcNow;

            var taskRequest = new TaskRequest
            {
                Environment = environment,
                Filename    = filename,
                Username    = username
            };

            try
            {
                // Wait 2 minutes for the tests to run, this can be made configurable later
                int taskId = Start(taskRequest);
                TestFileRunnerTaskInfo task = _fileQueue.GetTestFileTaskInfo(taskId);
                bool completed = task.CurrentTask.Wait(TimeSpan.FromMinutes(2));

                TimeSpan timeTaken = DateTime.UtcNow - startTime;

                return(_testFileResultFactory.Create(task, !completed, timeTaken));
            }
            catch (Exception ex)
            {
                TimeSpan timeTaken = DateTime.UtcNow - startTime;

                // Error
                return(new TestFileRunResult()
                {
                    Finished = false,
                    TimeTaken = timeTaken,
                    ErrorMessage = ex.ToString()
                });
            }
        }
Пример #2
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,
            });
        }