示例#1
0
        public void IntegrationCanBeDelayed()
        {
            string            enforcer = "BuildForcer";
            IntegrationResult result   = new IntegrationResult();

            result.ProjectName = (projectMock.Object as IProject).Name;
            result.Status      = IntegrationStatus.Success;
            // The following latch is needed to ensure the end assertions are not called before
            // the events have been fired. Because of the multi-threaded nature of the integrators
            // this can happen without any of the other latches being affected.
            ManualResetEvent latch = new ManualResetEvent(false);

            bool eventIntegrationStartedFired   = false;
            bool eventIntegrationCompletedFired = false;
            bool delayIntegration    = true;
            IntegrationStatus status = IntegrationStatus.Unknown;

            integrator.IntegrationStarted += delegate(object o, IntegrationStartedEventArgs a)
            {
                eventIntegrationStartedFired = true;
                if (delayIntegration)
                {
                    a.Result         = IntegrationStartedEventArgs.EventResult.Delay;
                    delayIntegration = !delayIntegration;
                }
            };
            integrator.IntegrationCompleted += delegate(object o, IntegrationCompletedEventArgs a)
            {
                eventIntegrationCompletedFired = true;
                status = a.Status;
                latch.Set();
            };

            LatchHelper integrationTriggerLatchHelper = new LatchHelper();

            integrationTriggerMock.Setup(_trigger => _trigger.Fire()).Verifiable();
            LatchHelper projectLatchHelper = new LatchHelper();

            projectMock.Setup(project => project.Integrate(It.Is <IntegrationRequest>(r => r.BuildCondition == BuildCondition.ForceBuild))).Returns(result).Verifiable();
            projectMock.Setup(project => project.NotifyPendingState()).Verifiable();
            projectMock.Setup(project => project.NotifySleepingState()).Callback(() => projectLatchHelper.SetLatch()).Verifiable();
            projectMock.SetupGet(project => project.MaxSourceControlRetries).Returns(5);
            projectMock.SetupGet(project => project.SourceControlErrorHandling).Returns(ThoughtWorks.CruiseControl.Core.Sourcecontrol.Common.SourceControlErrorHandlingPolicy.ReportEveryFailure);
            integrationTriggerMock.Setup(_trigger => _trigger.IntegrationCompleted()).Callback(() => integrationTriggerLatchHelper.SetLatch()).Verifiable();
            var parameters = new Dictionary <string, string>();

            integrator.Start();
            integrator.ForceBuild(enforcer, parameters);
            integrationTriggerLatchHelper.WaitForSignal();
            projectLatchHelper.WaitForSignal();
            VerifyAll();
            projectMock.VerifyNoOtherCalls();

            latch.WaitOne(2000, false);
            Assert.IsTrue(eventIntegrationStartedFired);
            Assert.IsTrue(eventIntegrationCompletedFired);
            Assert.AreEqual(IntegrationStatus.Success, status);
        }
示例#2
0
        public void ShouldContinueRunningIfNotToldToStop()
        {
            LatchHelper latchHelper = new LatchHelper();

            integrationTriggerMock.Setup(_trigger => _trigger.Fire()).Callback(() => latchHelper.SetLatch()).Returns(() => null);

            integrator.Start();
            latchHelper.WaitForSignal();
            Assert.AreEqual(ProjectIntegratorState.Running, integrator.State);
            projectMock.Verify(project => project.Integrate(It.IsAny <IntegrationRequest>()), Times.Never);
            integrationTriggerMock.Verify(_trigger => _trigger.IntegrationCompleted(), Times.Never);
            VerifyAll();
        }
示例#3
0
        public void TerminateWhenProjectIsntStarted()
        {
            LatchHelper latchHelper = new LatchHelper();

            integrationTriggerMock.Setup(_trigger => _trigger.Fire()).Callback(() => latchHelper.SetLatch()).Returns(() => null);

            integrator.Abort();
            Assert.AreEqual(ProjectIntegratorState.Unknown, integrator.State);
            projectMock.Verify(project => project.NotifyPendingState(), Times.Never);
            projectMock.Verify(project => project.Integrate(It.IsAny <IntegrationRequest>()), Times.Never);
            projectMock.Verify(project => project.NotifySleepingState(), Times.Never);
            integrationTriggerMock.Verify(_trigger => _trigger.IntegrationCompleted(), Times.Never);
            VerifyAll();
        }
示例#4
0
        public void Abort()
        {
            LatchHelper latchHelper = new LatchHelper();

            integrationTriggerMock.Setup(_trigger => _trigger.Fire()).Callback(() => latchHelper.SetLatch()).Returns(() => null);

            integrator.Start();
            latchHelper.WaitForSignal();
            Assert.AreEqual(ProjectIntegratorState.Running, integrator.State);
            integrator.Abort();
            integrator.WaitForExit();
            Assert.AreEqual(ProjectIntegratorState.Stopped, integrator.State);
            projectMock.Verify(project => project.NotifyPendingState(), Times.Never);
            projectMock.Verify(project => project.Integrate(It.IsAny <IntegrationRequest>()), Times.Never);
            projectMock.Verify(project => project.NotifySleepingState(), Times.Never);
            integrationTriggerMock.Verify(_trigger => _trigger.IntegrationCompleted(), Times.Never);
            VerifyAll();
        }
示例#5
0
        public void ShouldClearRequestQueueAsSoonAsRequestIsProcessed()
        {
            IntegrationRequest request            = new IntegrationRequest(BuildCondition.IfModificationExists, "intervalTrigger", null);
            LatchHelper        projectLatchHelper = new LatchHelper();

            projectMock.Setup(project => project.NotifyPendingState()).Verifiable();
            projectMock.Setup(project => project.Integrate(request)).Verifiable();
            projectMock.Setup(project => project.NotifySleepingState()).Callback(() => projectLatchHelper.SetLatch()).Verifiable();
            projectMock.SetupGet(project => project.MaxSourceControlRetries).Returns(5);
            projectMock.SetupGet(project => project.SourceControlErrorHandling).Returns(ThoughtWorks.CruiseControl.Core.Sourcecontrol.Common.SourceControlErrorHandlingPolicy.ReportEveryFailure);
            LatchHelper integrationTriggerLatchHelper = new LatchHelper();

            integrationTriggerMock.Setup(_trigger => _trigger.IntegrationCompleted()).Verifiable();
            integrationTriggerMock.Setup(_trigger => _trigger.Fire()).Callback(() => integrationTriggerLatchHelper.SetLatch()).Returns(() => null).Verifiable();
            integrator.Start();
            integrator.Request(request);
            projectLatchHelper.WaitForSignal();
            integrationTriggerLatchHelper.WaitForSignal();
            VerifyAll();
        }
示例#6
0
        public void VerifyStateAfterException()
        {
            string exceptionMessage = "Intentional exception";

            integrationTriggerMock.Setup(_trigger => _trigger.Fire()).Returns(ForceBuildRequest()).Verifiable();
            projectMock.Setup(project => project.NotifyPendingState()).Verifiable();
            projectMock.Setup(project => project.Integrate(It.Is <IntegrationRequest>(r => r.BuildCondition == BuildCondition.ForceBuild))).Throws(new CruiseControlException(exceptionMessage)).Verifiable();
            LatchHelper latchHelper = new LatchHelper();

            projectMock.Setup(project => project.NotifySleepingState()).Callback(() => latchHelper.SetLatch()).Verifiable();
            projectMock.SetupGet(project => project.MaxSourceControlRetries).Returns(5);
            projectMock.SetupGet(project => project.SourceControlErrorHandling).Returns(ThoughtWorks.CruiseControl.Core.Sourcecontrol.Common.SourceControlErrorHandlingPolicy.ReportEveryFailure);
            integrationTriggerMock.Setup(_trigger => _trigger.IntegrationCompleted()).Verifiable();

            integrator.Start();
            latchHelper.WaitForSignal();
            Assert.AreEqual(ProjectIntegratorState.Running, integrator.State);
            integrator.Stop(false);
            integrator.WaitForExit();
            Assert.AreEqual(ProjectIntegratorState.Stopped, integrator.State);
            VerifyAll();
        }
示例#7
0
        public void ForceBuild()
        {
            LatchHelper projectLatchHelper = new LatchHelper();

            projectMock.Setup(project => project.Integrate(It.Is <IntegrationRequest>(r => r.BuildCondition == BuildCondition.ForceBuild))).Verifiable();
            projectMock.Setup(project => project.NotifyPendingState()).Verifiable();
            projectMock.Setup(project => project.NotifySleepingState()).Callback(() => projectLatchHelper.SetLatch()).Verifiable();
            projectMock.SetupGet(project => project.MaxSourceControlRetries).Returns(5);
            projectMock.SetupGet(project => project.SourceControlErrorHandling).Returns(ThoughtWorks.CruiseControl.Core.Sourcecontrol.Common.SourceControlErrorHandlingPolicy.ReportEveryFailure);
            integrator.Start();

            LatchHelper integrationTriggerLatchHelper = new LatchHelper();

            integrationTriggerMock.Setup(_trigger => _trigger.IntegrationCompleted()).Callback(() => integrationTriggerLatchHelper.SetLatch()).Verifiable();
            var parameters = new Dictionary <string, string>();

            integrator.ForceBuild("BuildForcer", parameters);
            integrationTriggerLatchHelper.WaitForSignal();
            projectLatchHelper.WaitForSignal();
            VerifyAll();
            projectMock.VerifyNoOtherCalls();
            integrationTriggerMock.VerifyNoOtherCalls();
        }