示例#1
0
        public void RunPolicy_DueEvent_ShouldRunJob()
        {
            var chefRunner = new FakeChefRunner();
            var policy     = new FakeRunPolicy();

            CreateRunChefJobThatRunsJobsImmediately(chefRunner, policy);

            policy.FireDue();

            chefRunner.WasRun.Should().BeTrue("because a run of the job was due");
        }
示例#2
0
        public void Pause_ShouldMakeTheTaskNotReadyEvenWhenItIsDue()
        {
            var  policy             = new FakeRunPolicy();
            var  runChefJob         = CreateRunChefJob(runPolicy: policy);
            bool wasJobRunRequested = false;

            runChefJob.RunReady += (sender, run) => wasJobRunRequested = true;

            runChefJob.Pause();
            policy.FireDue();

            wasJobRunRequested.Should()
            .BeFalse("because the job is paused, even when the policy is due it shouldn't fire");
        }
示例#3
0
        public void Resume_ShouldMakeTheTaskRunnableAgain()
        {
            var  policy             = new FakeRunPolicy();
            var  runChefJob         = CreateRunChefJob(runPolicy: policy);
            bool wasJobRunRequested = false;

            runChefJob.RunReady += (sender, run) => wasJobRunRequested = true;

            runChefJob.Pause();
            runChefJob.Resume();
            policy.FireDue();

            wasJobRunRequested.Should()
            .BeTrue("because the job is resumed it should request to be ran");
        }
示例#4
0
        public void Due_ShouldNotRequestRunWhenPreviousRunIsStillRunning()
        {
            var policy     = new FakeRunPolicy();
            var runChefJob = CreateRunChefJob(runPolicy: policy);

            policy.FireDue(); // which creates a job that doesn't run, so it's not done yet

            var wasRunReady = false;

            runChefJob.RunReady += (sender, run) => wasRunReady = true;

            policy.FireDue();

            wasRunReady.Should().BeFalse("because the original job has not finished yet");
        }
示例#5
0
        public void Due_ShouldNotFireWhenAnotherPolicyIsUsed()
        {
            var policy     = new FakeRunPolicy();
            var runChefJob = CreateRunChefJob(runPolicy: policy);

            bool wasRunReady = false;

            runChefJob.RunReady += (sender, run) => wasRunReady = true;

            runChefJob.RunPolicy = new FakeRunPolicy();

            policy.FireDue();

            wasRunReady.Should().BeFalse("because a different policy is in place now");
        }
示例#6
0
        public void Due_ShouldFireWhenPreviousRunFinishedRunning()
        {
            var policy     = new FakeRunPolicy();
            var runChefJob = CreateRunChefJob(runPolicy: policy);

            runChefJob.RunReady += RunJobImmediately;

            policy.FireDue();

            bool wasRunReady = false;

            runChefJob.RunReady += (sender, run) => wasRunReady = true;

            policy.FireDue();

            wasRunReady.Should().BeTrue("because the previous run already ran, we're ready to run again");
        }