WaitForJobCompletion() 공개 메소드

public WaitForJobCompletion ( string messageID, System.TimeSpan maxWait ) : JobCompleted
messageID string
maxWait System.TimeSpan
리턴 JobCompleted
        public void EnsureJobsQueuedAfterMaxVMsRunningReached()
        {
            sut.EmulateServiceStart(null);
            DirectoryInfo tempDir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tempdll"));
            tempDir.Create();
            string existingMaxVMSetting = ConfigurationManager.AppSettings["maxvms"];
            ConfigurationManager.AppSettings["maxvms"] = "1";
            try
            {
                List<ExecutablePackage> packages = new List<ExecutablePackage>();
                ExecutablePackage package = new ExecutablePackage("mock.xml", tempDir.FullName, "TestJobManager.dll", "TestJobManager.MockJobRunner", new SerializableDictionary<string, string>(), new SerializableDictionary<string, string>());
                packages.Add(package);
                Job j1 = new Job("nobuildpath", "MockVMConfig1", new SerializableDictionary<string, string>(), packages, new SerializableDictionary<string, string>());
                Job j2 = new Job("nobuildpath", "MockVMConfig2", new SerializableDictionary<string, string>(), packages, new SerializableDictionary<string, string>());
                MessageSendRecieve msr = new MessageSendRecieve(new DirectoryInfo(inboxPath), new DirectoryInfo(outboxPath));
                DateTime queuedJobsDateTime = DateTime.Now;
                string job2msgID = msr.QueueJob(j1);
                string job1msgID = msr.QueueJob(j2);
                //wait for job 1 to start
                Assert.True(WaitForVMAction(vmHash["MockVMName1"], VMActionType.Start, queuedJobsDateTime, TimeSpan.FromSeconds(5)));
                //make sure job 2 doesn't start/hasn't started
                Assert.False(WaitForVMAction(vmHash["MockVMName2"], VMActionType.Start, queuedJobsDateTime, TimeSpan.FromSeconds(1)));

                //send request for job 1
                AutomationMessage m = new AutomationMessage(new SimpleRequest(SimpleRequests.JobRequest));
                m.From = "MockVMName1";
                Job j = msr.WaitForJob(msr.Send(m), DEFAULT_WAIT);
                Assert.That(j, Is.Not.Null);
                //send finished for job 1
                DateTime finishedSentDateTime = DateTime.Now;
                msr.ReportJobStatus(new JobCompleted(j1, new JobResult()));

                //wait for job 2 to start
                Assert.True(WaitForVMAction(vmHash["MockVMName2"], VMActionType.Start, finishedSentDateTime, TimeSpan.FromSeconds(5)));
                //send request for job 2
                m = new AutomationMessage(new SimpleRequest(SimpleRequests.JobRequest));
                m.From = "MockVMName2";
                j = msr.WaitForJob(msr.Send(m), DEFAULT_WAIT);
                Assert.That(j, Is.Not.Null);
                //send finished for job2
                msr.ReportJobStatus(new JobCompleted(j2, new JobResult()));

                Assert.That(msr.WaitForJobCompletion(job1msgID, DEFAULT_WAIT), Is.Not.Null);
                Assert.That(msr.WaitForJobCompletion(job2msgID, DEFAULT_WAIT), Is.Not.Null);

                sut.EmulateServiceStop();

                VerifyAppLogDoesNotContain(EventLogEntryType.Warning, testStart);
                VerifyAppLogDoesNotContain(EventLogEntryType.Error, testStart);

                VerifyMockVMActionInvoked(vmHash["MockVMName1"], VMActionType.RevertToNamedSnapshot, "Snapshot1");
                VerifyMockVMActionInvoked(vmHash["MockVMName2"], VMActionType.RevertToNamedSnapshot, "Snapshot2");
            }
            finally
            {
                tempDir.Delete(true);
                ConfigurationManager.AppSettings["maxvms"] = existingMaxVMSetting;
            }
        }
예제 #2
0
        public static int Main(string[] args)
        {
            try
            {
                if (args.Length == 2 || args.Length == 3)
                {
                    string pathToBuildOutput = args[0];
                    string pathToJobCollectionXML = args[1];

                    if (!File.Exists(pathToJobCollectionXML))
                    {
                        pathToJobCollectionXML = Path.Combine(pathToBuildOutput, pathToJobCollectionXML);
                    }

                    JobCollectionSet set = new JobCollectionSet(new FileInfo(pathToJobCollectionXML));
                    List<Job> jobs = set.CreateJobs(pathToBuildOutput);

                    MessageSendRecieve msr = new MessageSendRecieve(AppConfig.ServerInbox, AppConfig.ServerOutbox);

                    List<string> sentMessages = new List<string>();

                    foreach (Job j in jobs)
                    {
                        Console.WriteLine("Queueing Job " + j.JobID + " for config " + j.Configuration);
                        sentMessages.Add(msr.QueueJob(j));
                    }

                    string resultBasePath = Path.Combine(ASSEMBLY_DIR.FullName, "result");
                    if (args.Length == 3)
                    {
                        string outputPath = args[2];
                        if (Directory.Exists(outputPath))
                        {
                            resultBasePath = outputPath;
                        }
                    }

                    if (!Directory.Exists(resultBasePath))
                    {
                        Directory.CreateDirectory(resultBasePath);
                    }

                    Console.WriteLine("Waiting for Jobs to Finish");

                    bool executionSuccessOverall = true;

                    foreach (string sentMessageID in sentMessages)
                    {
                        JobCompleted jobComplete = msr.WaitForJobCompletion(sentMessageID, TimeSpan.FromDays(2));

                        string resultDirPath = Path.Combine(resultBasePath, jobComplete.Job.Configuration + "_" + jobComplete.Job.JobID);

                        DirectoryInfo resultDir = new DirectoryInfo(resultDirPath);
                        if (!resultDir.Exists)
                        {
                            resultDir.Create();
                        }

                        using (TextWriter tw = new StreamWriter(Path.Combine(resultDir.FullName, "result.xml")))
                        {
                            tw.Write(jobComplete.Result.ToXML());
                        }
                        using (TextWriter tw = new StreamWriter(Path.Combine(resultDir.FullName, "job.xml")))
                        {
                            tw.Write(jobComplete.Job.ToXML());
                        }

                        Console.WriteLine("Job: " + jobComplete.Job.JobID);
                        Console.WriteLine("Success = " + jobComplete.Result.Success);

                        foreach (ExecutionResult er in jobComplete.Result.ExecutionResults)
                        {
                            if (er.Errors.Count > 0)
                            {
                                Console.WriteLine("Errors:");
                                foreach (var error in er.Errors)
                                {
                                    Console.WriteLine(error);
                                }
                            }
                            Console.WriteLine(er.Attachments.Count + " attachments");
                            foreach (FileData attachement in er.Attachments)
                            {
                                attachement.WriteToDirRename(resultDir);
                            }
                        }

                        int i = 0;
                        if (jobComplete.Result.Logs != null)
                        {
                            foreach (FileData logData in jobComplete.Result.Logs)
                            {
                                if (logData.Data.Length > 0)
                                {
                                    logData.WriteToFile(new FileInfo(Path.Combine(resultDir.FullName, "log" + i + ".txt")));
                                    i++;
                                }
                            }
                        }

                        if (!jobComplete.Result.Completed || jobComplete.Result.Errors.Count > 0)
                        {
                            executionSuccessOverall = false;
                        }
                    }
                    string[] afterJobExeParts = AppConfig.RunAfterJob.Split(' ');
                    if (afterJobExeParts.Length >= 2)
                    {
                        string exeFileName = afterJobExeParts[0];
                        if (!File.Exists(exeFileName))
                        {
                            exeFileName = Path.Combine(ASSEMBLY_DIR.FullName, exeFileName);
                        }
                        if (File.Exists(exeFileName))
                        {
                            string args2 = string.Join(" ", afterJobExeParts, 1, afterJobExeParts.Length - 1);
                            args2 = args2.Replace("$(JobResultPath)", resultBasePath);
                            using (System.Diagnostics.Process p = System.Diagnostics.Process.Start(exeFileName, args2))
                            {
                                p.WaitForExit();
                            }
                        }
                    }

                    if (executionSuccessOverall)
                    {
                        return 0;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    Console.WriteLine("Usage: JobManagerConsole.exe [Path_To_Build_Output] [Path_To_JobCollection_XML] ([OutputPath])");
                    Console.WriteLine();
                    //Console.WriteLine(@"Example: JobManagerConsole.exe WinXP_32 \\rockhopbuild\Hammer\HammerTools\DailyBuilds\LatestISO\40-00118-01.iso \\ryanadams2\HammerAuto WinToolsTestAutomation.dll WinToolsTestAutomation.Runner");
                    return -1;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An exception has occured");
                Console.WriteLine(ex.ToString());
                return -1;
            }
        }
        public void TestRunNonExistantVMConfig()
        {
            sut.EmulateServiceStart(null);
            List<ExecutablePackage> packages = new List<ExecutablePackage>();
            Job j1 = new Job("nobuildpath", "NonExistantVMConfig", new SerializableDictionary<string, string>(), null, new SerializableDictionary<string, string>());
            MessageSendRecieve msr = new MessageSendRecieve(new DirectoryInfo(inboxPath), new DirectoryInfo(outboxPath));
            DateTime queuedJobsDateTime = DateTime.Now;
            string job1msgID = msr.QueueJob(j1);

            //wait for job completion
            JobCompleted jobCompleted = msr.WaitForJobCompletion(job1msgID, DEFAULT_WAIT);

            sut.EmulateServiceStop();

            Assert.That(jobCompleted, Is.Not.Null);
            Assert.That(jobCompleted.Job, Is.Not.Null);
            Assert.That(jobCompleted.Result, Is.Not.Null);
            Assert.That(jobCompleted.Result.Errors, Is.Not.Empty);
            VerifyStringInList(jobCompleted.Result.Errors, "Could not find a VM suitable for this configuration(NonExistantVMConfig)");

            VerifyAppLogDoesNotContain(EventLogEntryType.Warning, testStart);
            VerifyAppLogDoesNotContain(EventLogEntryType.Error, testStart);
        }
        public void TestNullPackageList()
        {
            sut.EmulateServiceStart(null);
            Job j1 = new Job("nobuildpath", "MockVMConfig1", new SerializableDictionary<string, string>(), null, new SerializableDictionary<string, string>());
            MessageSendRecieve msr = new MessageSendRecieve(new DirectoryInfo(inboxPath), new DirectoryInfo(outboxPath));
            DateTime queuedJobsDateTime = DateTime.Now;
            string job1msgID = msr.QueueJob(j1);

            //wait for job completion
            JobCompleted jobCompleted = msr.WaitForJobCompletion(job1msgID, DEFAULT_WAIT);

            sut.EmulateServiceStop();

            VerifyAppLogDoesNotContain(EventLogEntryType.Warning, testStart);
            VerifyAppLogDoesNotContain(EventLogEntryType.Error, testStart);

            Assert.That(jobCompleted, Is.Not.Null);
            Assert.That(jobCompleted.Job, Is.Not.Null);
            Assert.That(jobCompleted.Result, Is.Not.Null);
            Assert.That(jobCompleted.Result.Errors, Is.Not.Empty);
            VerifyStringInList(jobCompleted.Result.Errors, "Job does not have any packages defined");
        }
        public void TestNullISOs()
        {
            sut.EmulateServiceStart(null);
            DirectoryInfo tempDir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tempdll"));
            tempDir.Create();
            try
            {
                List<ExecutablePackage> packages = new List<ExecutablePackage>();
                ExecutablePackage package = new ExecutablePackage("mock.xml", tempDir.FullName, "TestJobManager.dll", "TestJobManager.MockJobRunner", new SerializableDictionary<string, string>(), new SerializableDictionary<string, string>());
                packages.Add(package);

                Job j1 = new Job(null, "MockVMConfig1", null, packages, new SerializableDictionary<string, string>());
                MessageSendRecieve msr = new MessageSendRecieve(new DirectoryInfo(inboxPath), new DirectoryInfo(outboxPath));
                DateTime queuedJobsDateTime = DateTime.Now;
                string job1msgID = msr.QueueJob(j1);

                //wait for job 1 to start
                Assert.True(WaitForVMAction(vmHash["MockVMName1"], VMActionType.Start, queuedJobsDateTime, TimeSpan.FromSeconds(5)));

                //send request for job 1
                AutomationMessage m = new AutomationMessage(new SimpleRequest(SimpleRequests.JobRequest));
                m.From = "MockVMName1";
                Job j = msr.WaitForJob(msr.Send(m), DEFAULT_WAIT);
                Assert.That(j, Is.Not.Null);
                Assert.That(j.JobID, Is.EqualTo(j1.JobID));

                //send finished for job 1
                DateTime finishedSentDateTime = DateTime.Now;
                JobResult jr = new JobResult();
                jr.Completed = true;
                ExecutionResult er = new ExecutionResult();
                er.Success = true;
                jr.ExecutionResults.Add(er);
                msr.ReportJobStatus(new JobCompleted(j1, jr));

                //wait for job completion
                JobCompleted jobCompleted = msr.WaitForJobCompletion(job1msgID, DEFAULT_WAIT);

                sut.EmulateServiceStop();

                VerifyAppLogDoesNotContain(EventLogEntryType.Warning, testStart);
                VerifyAppLogDoesNotContain(EventLogEntryType.Error, testStart);

                Assert.That(jobCompleted, Is.Not.Null);
                Assert.That(jobCompleted.Job, Is.Not.Null);
                Assert.That(jobCompleted.Result, Is.Not.Null);
                Assert.That(jobCompleted.Result.Errors, Is.Empty);
                Assert.That(jobCompleted.Result.Success, Is.True);
                Assert.That(jobCompleted.Result.Completed, Is.True);
            }
            finally
            {
                tempDir.Delete(true);
            }
        }
        public void TestNullDirPathInJob()
        {
            sut.EmulateServiceStart(null);
            List<ExecutablePackage> packages = new List<ExecutablePackage>();
            ExecutablePackage package = new ExecutablePackage("mock.xml", null, "TestJobManager.dll", "TestJobManager.MockJobRunner", new SerializableDictionary<string, string>(), new SerializableDictionary<string, string>());
            packages.Add(package);
            Job j1 = new Job("nobuildpath", "MockVMConfig1", new SerializableDictionary<string, string>(), packages, new SerializableDictionary<string, string>());
            MessageSendRecieve msr = new MessageSendRecieve(new DirectoryInfo(inboxPath), new DirectoryInfo(outboxPath));
            DateTime queuedJobsDateTime = DateTime.Now;
            string job1msgID = msr.QueueJob(j1);

            //wait for job completion
            JobCompleted jobCompleted = msr.WaitForJobCompletion(job1msgID, DEFAULT_WAIT);

            sut.EmulateServiceStop();

            Assert.That(jobCompleted, Is.Not.Null);
            Assert.That(jobCompleted.Job, Is.Not.Null);
            Assert.That(jobCompleted.Result, Is.Not.Null);
            Assert.That(jobCompleted.Result.Errors, Is.Not.Empty);
            VerifyStringInList(jobCompleted.Result.Errors, "Exception: Value cannot be null.\nParameter name: path");

            VerifyAppLogDoesNotContain(EventLogEntryType.Warning, testStart);
            VerifyAppLogDoesNotContain(EventLogEntryType.Error, testStart);
        }