Beispiel #1
0
        /// <summary>
        /// Dispatch task to jobs based on the test suites defined for dependance
        /// </summary>
        /// <param name="task"></param>
        /// <param name="allCasesForTask"></param>
        private static void DispatchTaskToJobs(AutomationTask task, List<int> allCasesForTask)
        {
            int i = 0;
            string message = string.Empty;
            //Store whether the test cases have been dispatched to job or not based on dependency test suite
            Dictionary<string, bool> testCaseDispatchIndicator = new Dictionary<string, bool>();
            int testcaseProviderId = Product.GetProductByID(task.ProductId.GetValueOrDefault()).TestCaseProviderId.GetValueOrDefault();

            List<TestSuite> dependenceSuites = TestSuite.GetTestSuitesByProviderIdAndType(testcaseProviderId, SuiteType.Dependence).ToList();
            foreach (TestSuite dependenceSuite in dependenceSuites)
            {
                string testCasesForJob = string.Empty;
                foreach (string tc in dependenceSuite.TestCases.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (allCasesForTask.Contains(int.Parse(tc)) && !testCaseDispatchIndicator.ContainsKey(tc))
                    {
                        testCasesForJob = testCasesForJob == string.Empty ? tc : testCasesForJob + ',' + tc;
                        testCaseDispatchIndicator.Add(tc, true);
                    }
                }
                if (testCasesForJob != string.Empty)
                {
                    // Create AutomationJob
                    ++i;
                    AutomationJob job = new AutomationJob()
                    {
                        Name = "JobForTask " + task.TaskId.ToString() + "_" + i.ToString(),
                        Status = (int)JobStatus.Assigned,
                        Type = (int)JobType.Sequence,
                        Priority = task.Priority,
                        RetryTimes = 1,
                        Timeout = ATFConfiguration.GetIntValue("DefaultAutomationJobTimeout"),//1 hours
                        CreateDate = System.DateTime.UtcNow,
                        ModifyDate = System.DateTime.UtcNow,
                        CreateBy = 0,//automation, pre-defined user
                        ModifyBy = 0,//automation, pre-defined user
                    };
                    AutomationJob bCreateJob = AutomationJob.CreateJob(job);

                    message = string.Format("Job [{0}] is created.", bCreateJob.JobId);
                    task.AddProgressInformation(message);
                    ATFEnvironment.Log.logger.Info(message);

                    TaskJobMap map = new TaskJobMap()
                    {
                        TaskId = task.TaskId,
                        JobId = job.JobId,
                    };
                    TaskJobMap.CreateMap(map);

                    foreach (string id in testCasesForJob.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        TestCaseExecution ex = new TestCaseExecution()
                        {
                            TestCaseId = int.Parse(id),
                            JobId = job.JobId,
                            Status = (int)ExecutionStatus.NotRunning,
                            StartTime = null,
                            EndTime = null,
                            RetryTimes = 0,
                            Timeout = ATFEnvironment.DefaultTestCaseTimeout,
                        };
                        TestCaseExecution exInDB = TestCaseExecution.CreateExecution(ex);

                        message = string.Format("Execution [{0}] is created.", exInDB.ExecutionId);
                        //task.AddProgressInformation(message);
                        ATFEnvironment.Log.logger.Info(message);

                        TestResult result = new TestResult
                        {
                            ExecutionId = exInDB.ExecutionId,
                            Result = (int)ResultType.NotRun,
                            IsTriaged = false,
                            TriagedBy = null,
                            Files = null,
                        };
                        TestResult.CreateRunResult(result);

                        message = string.Format("Test result [{0}] is created.", result.ResultId);
                        //task.AddProgressInformation(message);
                        ATFEnvironment.Log.logger.Info(message);
                    }
                }
            }

            foreach (int testcaseId in allCasesForTask)
            {
                if (!testCaseDispatchIndicator.ContainsKey(testcaseId.ToString()))//not dispatched to jobs yet
                {
                    // Create AutomationJob
                    ++i;
                    AutomationJob job = new AutomationJob()
                    {
                        Name = "JobForTask " + task.TaskId.ToString() + "_" + i.ToString(),
                        Status = (int)JobStatus.Assigned,
                        Type = (int)JobType.Sequence,
                        Priority = task.Priority,
                        RetryTimes = 1,
                        Timeout = ATFConfiguration.GetIntValue("DefaultAutomationJobTimeout"),//1 hours
                        CreateDate = System.DateTime.UtcNow,
                        ModifyDate = System.DateTime.UtcNow,
                        CreateBy = 0,//automation, pre-defined user
                        ModifyBy = 0,//automation, pre-defined user
                    };
                    AutomationJob bCreateJob = AutomationJob.CreateJob(job);

                    message = string.Format("Job [{0}] is created.", bCreateJob.JobId);
                    task.AddProgressInformation(message);
                    ATFEnvironment.Log.logger.Info(message);

                    TaskJobMap map = new TaskJobMap()
                    {
                        TaskId = task.TaskId,
                        JobId = job.JobId,
                    };
                    TaskJobMap.CreateMap(map);

                    TestCaseExecution ex = new TestCaseExecution()
                    {
                        TestCaseId = testcaseId,
                        JobId = job.JobId,
                        Status = (int)ExecutionStatus.NotRunning,
                        StartTime = null,
                        EndTime = null,
                        RetryTimes = 0,
                        Timeout = ATFEnvironment.DefaultTestCaseTimeout,
                    };
                    TestCaseExecution exInDB = TestCaseExecution.CreateExecution(ex);

                    message = string.Format("Execution [{0}] is created.", exInDB.ExecutionId);
                    //task.AddProgressInformation(message);
                    ATFEnvironment.Log.logger.Info(message);

                    TestResult result = new TestResult
                    {
                        ExecutionId = exInDB.ExecutionId,
                        Result = (int)ResultType.NotRun,
                        IsTriaged = false,
                        TriagedBy = null,
                        Files = null,
                    };
                    TestResult.CreateRunResult(result);

                    message = string.Format("Test result [{0}] is created.", result.ResultId);
                    //task.AddProgressInformation(message);
                    ATFEnvironment.Log.logger.Info(message);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Check whether all the jobs has been finished or not of the task
 /// 1. The 
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 private static bool AreAllJobsOfTaskFinished(AutomationTask task)
 {
     List<AutomationJob> jobs = task.GetJobs();
     if (jobs == null || jobs.Count() <= 0)
     {
         ATFEnvironment.Log.logger.Warn("No jobs for Task " + task.TaskId.ToString());
         task.SetTaskStatus(TaskStatus.Failed);
         ATFEnvironment.Log.logger.Info("Change Task " + task.TaskId.ToString() + " status from Dispatched to Failed");
         task.AddProgressInformation("Change status: Dispatched to " + "Failed");
         return true;
     }
     else
     {
         foreach (AutomationJob job in jobs)
         {
             if (job.Status != (int)JobStatus.End
                 && job.Status != (int)JobStatus.Failed
                 && job.Status != (int)JobStatus.Complete
                 && job.Status != (int)JobStatus.Cancelled
                 && job.Status != (int)JobStatus.Timeout)
             {
                 return false;
             }
         }
         return true;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Check whether one of the job has been started of the task
 /// </summary>
 /// <param name="task">task</param>
 /// <returns></returns>
 private static bool IsOneJobOfTaskStarted(AutomationTask task)
 {
     List<AutomationJob> jobs = task.GetJobs();
     if (jobs == null || jobs.Count() <= 0)
     {
         ATFEnvironment.Log.logger.Warn("No jobs for Task " + task.TaskId.ToString());
         task.SetTaskStatus(TaskStatus.Failed);
         ATFEnvironment.Log.logger.Info("Change Task " + task.TaskId.ToString() + " status from Dispatched to Failed");
         task.AddProgressInformation("Change status: Dispatched to " + "Failed");
         return false;
     }
     else
     {
         foreach (AutomationJob job in jobs)
         {
             if (job.Status != (int)JobStatus.Assigned)//The initial status of job
             {
                 return true;
             }
         }
         return false;
     }
 }
Beispiel #4
0
 private static bool IsBuildOfTaskReady(AutomationTask task)
 {
     Build build = Build.GetBuildById(task.BuildId);
     switch (build.Status)
     {
         case (int)BuildStatus.Success:
             {
                 string message = string.Format("The build [{0}] is ready.", build.Name);
                 ATFEnvironment.Log.logger.Info(message);
                 task.AddProgressInformation(message);
                 return true;
             }
         case (int)BuildStatus.Failed:
             {
                 string message = string.Format("The build [{0}] is failed.", build.Name);
                 ATFEnvironment.Log.logger.Info(message);
                 task.AddProgressInformation(message);
                 task.SetTaskStatus(TaskStatus.Failed);
                 return false;
             }
         case (int)BuildStatus.NotExist:
             {
                 string message = string.Format("The build [{0}] doesn't exist.", build.Name);
                 ATFEnvironment.Log.logger.Info(message);
                 task.AddProgressInformation(message);
                 task.SetTaskStatus(TaskStatus.Failed);
                 return false;
             }
         case (int)BuildStatus.Delete:
             {
                 string message = string.Format("The build [{0}] has been deleted.", build.Name);
                 ATFEnvironment.Log.logger.Info(message);
                 task.AddProgressInformation(message);
                 task.SetTaskStatus(TaskStatus.Failed);
                 return false;
             }
         default:
             {
                 string message = string.Format("The status of build {0} is invalid.", build.Name);
                 ATFEnvironment.Log.logger.Error(message);
                 task.AddProgressInformation(message);
                 task.SetTaskStatus(TaskStatus.Failed);
                 return false;
             }
     }
 }
Beispiel #5
0
 private static bool GetSupporttedEnvironmentAndCheckStatusOfItForTask(AutomationTask task)
 {
     SupportedEnvironment supEnv = SupportedEnvironment.GetSupportedEnvironmentById(task.EnvironmentId);
     if (supEnv == null)
     {
         ATFEnvironment.Log.logger.Error("Task: " + task.TaskId.ToString() + " ,Supported Environment ERROR");
         task.AddProgressInformation("Supported Environment ERROR");
         task.SetTaskStatus(TaskStatus.Failed);
         return false;
     }
     else
     {
         string message = string.Format("The support environment is ready for task [{0}]", task.Name);
         ATFEnvironment.Log.logger.Info(message);
         task.AddProgressInformation(message);
         return true;
     }
 }
Beispiel #6
0
        private static bool GetBuildAndCheckStatusOfItForTask(AutomationTask task)
        {
            //if build id = 0, we need to get the latest mainline build for this task
            if (task.BuildId == 0)
            {
                Build latestBuild = BuildManager.GetLatestBuild(task);
                if (null != latestBuild)
                {
                    string message = string.Format("The latest mainline build is {0}", latestBuild.Name);
                    ATFEnvironment.Log.logger.Info(message);
                    task.AddProgressInformation(message);
                    task.SetBuild(latestBuild.BuildId);
                }
                else
                {
                    string message = string.Format("Could not find the latest build for task {0}", task.Name);
                    ATFEnvironment.Log.logger.Error(message);
                    task.AddProgressInformation(message);
                    task.SetTaskStatus(TaskStatus.Failed);
                    return false;
                }
            }

            // Check whether build is ready
            if (!IsBuildOfTaskReady(task))
            {
                return false;
            }
            else
            {
                return true;
            }
        }