diff --git a/actor/v7action/application.go b/actor/v7action/application.go index cb373e53d65..95f1abb4694 100644 --- a/actor/v7action/application.go +++ b/actor/v7action/application.go @@ -312,6 +312,11 @@ func (actor Actor) PollStartForRolling(app resources.Application, deploymentGUID for { select { case <-timeout: + warnings, err := actor.CancelDeployment(deploymentGUID) + allWarnings = append(allWarnings, warnings...) + if err != nil { + return allWarnings, err + } return allWarnings, actionerror.StartupTimeoutError{Name: app.Name} case <-timer.C(): if !isDeployed(deployment) { diff --git a/actor/v7action/application_test.go b/actor/v7action/application_test.go index 85003bd3704..4d02f5c565c 100644 --- a/actor/v7action/application_test.go +++ b/actor/v7action/application_test.go @@ -1200,9 +1200,13 @@ var _ = Describe("Application Actions", func() { ccv3.Warnings{"get-deployment-warning"}, nil, ) + fakeCloudControllerClient.CancelDeploymentReturns( + ccv3.Warnings{"cancel-deployment-warning"}, + nil, + ) }) - It("returns a timeout error and any warnings", func() { + It("returns a timeout error and any warnings and cancels the deployment", func() { // initial tick fakeClock.WaitForNWatchersAndIncrement(1*time.Millisecond, 2) @@ -1211,12 +1215,43 @@ var _ = Describe("Application Actions", func() { // timeout tick fakeClock.Increment(1 * time.Millisecond) + Eventually(fakeCloudControllerClient.CancelDeploymentCallCount).Should(Equal(1)) + // wait for func to finish Eventually(done).Should(Receive(BeTrue())) Expect(executeErr).To(MatchError(actionerror.StartupTimeoutError{})) - Expect(warnings).To(ConsistOf("get-deployment-warning")) + Expect(warnings).To(ConsistOf("get-deployment-warning", "cancel-deployment-warning")) + }) + + When("the cancel deployment fails", func() { + BeforeEach(func() { + fakeCloudControllerClient.CancelDeploymentReturns( + ccv3.Warnings{"cancel-deployment-warning"}, + errors.New("cancel-deployment-error"), + ) + }) + + It("returns a timeout error and any warnings and cancels the deployment", func() { + // initial tick + fakeClock.WaitForNWatchersAndIncrement(1*time.Millisecond, 2) + + Eventually(fakeCloudControllerClient.GetDeploymentCallCount).Should(Equal(1)) + + // timeout tick + fakeClock.Increment(1 * time.Millisecond) + + Eventually(fakeCloudControllerClient.CancelDeploymentCallCount).Should(Equal(1)) + + // wait for func to finish + Eventually(done).Should(Receive(BeTrue())) + + Expect(executeErr).To(MatchError("cancel-deployment-error")) + Expect(warnings).To(ConsistOf("get-deployment-warning", "cancel-deployment-warning")) + }) + }) + }) When("the processes dont become healthy", func() {