diff --git a/depot/steps/readiness_health_check_step.go b/depot/steps/readiness_health_check_step.go index f91d6908..d85f6961 100644 --- a/depot/steps/readiness_health_check_step.go +++ b/depot/steps/readiness_health_check_step.go @@ -65,9 +65,13 @@ func (step *readinessHealthCheckStep) runUntilReadyProcess(signals <-chan os.Sig return err } step.logger.Info("transitioned-to-ready") - step.readinessChan <- IsReady - fmt.Fprint(step.logStreamer.Stdout(), "Container passed the readiness health check. Container marked ready and added to route pool.\n") - return nil + select { + case step.readinessChan <- IsReady: + fmt.Fprint(step.logStreamer.Stdout(), "Container passed the readiness health check. Container marked ready and added to route pool.\n") + return nil + case <-signals: + return new(CancelledError) + } case s := <-signals: untilReadyProcess.Signal(s) <-untilReadyProcess.Wait() @@ -81,9 +85,13 @@ func (step *readinessHealthCheckStep) runUntilFailureProcess(signals <-chan os.S case err := <-untilFailureProcess.Wait(): if err != nil { step.logger.Info("transitioned-to-not-ready") - fmt.Fprint(step.logStreamer.Stdout(), "Container failed the readiness health check. Container marked not ready and removed from route pool.\n") - step.readinessChan <- IsNotReady - return nil + select { + case step.readinessChan <- IsNotReady: + fmt.Fprint(step.logStreamer.Stdout(), "Container failed the readiness health check. Container marked not ready and removed from route pool.\n") + return nil + case <-signals: + return new(CancelledError) + } } step.logger.Error("unexpected-until-failure-check-result", err) return nil diff --git a/depot/steps/readiness_health_check_step_test.go b/depot/steps/readiness_health_check_step_test.go index 9f50a028..4bd57641 100644 --- a/depot/steps/readiness_health_check_step_test.go +++ b/depot/steps/readiness_health_check_step_test.go @@ -2,6 +2,7 @@ package steps_test import ( "errors" + "fmt" "os" "code.cloudfoundry.org/executor/depot/log_streamer/fake_log_streamer" @@ -205,6 +206,33 @@ var _ = Describe("NewReadinessHealthCheckStep", func() { }) }) + Context("while waiting on the readines channel to receive", func() { + Context("while doing the untilReadyCheck", func() { + JustBeforeEach(func() { + Eventually(untilReadyCheck.RunCallCount).Should(Equal(1)) + untilReadyCheck.TriggerExit(nil) + }) + It("cancels the in-flight check", func() { + process.Signal(os.Interrupt) + Eventually(process.Wait()).Should(Receive(Equal(new(steps.CancelledError)))) + }) + }) + Context("while doing the untilFailureCheck", func() { + JustBeforeEach(func() { + untilReadyCheck.TriggerExit(nil) + state := <-readinessChan + Expect(state).To(Equal(steps.IsReady)) + Eventually(untilFailureCheck.RunCallCount).Should(Equal(1)) + }) + + It("cancels the in-flight check", func() { + untilFailureCheck.TriggerExit(fmt.Errorf("meow")) + process.Signal(os.Interrupt) + Eventually(process.Wait()).Should(Receive(Equal(new(steps.CancelledError)))) + }) + }) + }) + Context("while doing the untilFailure check", func() { JustBeforeEach(func() { untilReadyCheck.TriggerExit(nil) @@ -216,7 +244,7 @@ var _ = Describe("NewReadinessHealthCheckStep", func() { It("cancels the in-flight check", func() { process.Signal(os.Interrupt) Eventually(untilFailureCheck.WaitForCall()).Should(Receive(Equal(os.Interrupt))) - untilFailureCheck.TriggerExit(nil) + untilFailureCheck.TriggerExit(fmt.Errorf("meow")) Eventually(process.Wait()).Should(Receive(Equal(new(steps.CancelledError)))) }) })