It("evacuates the lrp", func() { Expect(fakeBBS.EvacuateClaimedActualLRPCallCount()).To(Equal(1)) actualLRPKey, actualLRPContainerKey := fakeBBS.EvacuateClaimedActualLRPArgsForCall(0) Expect(*actualLRPKey).To(Equal(lrpKey)) Expect(*actualLRPContainerKey).To(Equal(lrpInstanceKey)) }) Context("when the evacuation returns successfully", func() { BeforeEach(func() { fakeBBS.EvacuateClaimedActualLRPReturns(false, nil) }) It("deletes the container", func() { Expect(fakeContainerDelegate.DeleteContainerCallCount()).To(Equal(1)) _, actualContainerGuid := fakeContainerDelegate.DeleteContainerArgsForCall(0) Expect(actualContainerGuid).To(Equal(container.Guid)) }) }) Context("when the evacuation returns that it failed to unclaim the LRP", func() { BeforeEach(func() { fakeBBS.EvacuateClaimedActualLRPReturns(false, models.ErrActualLRPCannotBeUnclaimed) }) It("deletes the container", func() { Expect(fakeContainerDelegate.DeleteContainerCallCount()).To(Equal(1)) _, actualContainerGuid := fakeContainerDelegate.DeleteContainerArgsForCall(0) Expect(actualContainerGuid).To(Equal(container.Guid)) }) })
It("claims the actualLRP in the bbs", func() { Expect(bbsClient.ClaimActualLRPCallCount()).To(Equal(1)) processGuid, index, instanceKey := bbsClient.ClaimActualLRPArgsForCall(0) Expect(processGuid).To(Equal(expectedLrpKey.ProcessGuid)) Expect(int32(index)).To(Equal(expectedLrpKey.Index)) Expect(*instanceKey).To(Equal(expectedInstanceKey)) }) Context("when claiming fails because ErrActualLRPCannotBeClaimed", func() { BeforeEach(func() { bbsClient.ClaimActualLRPReturns(models.ErrActualLRPCannotBeClaimed) }) It("deletes the container", func() { Expect(containerDelegate.DeleteContainerCallCount()).To(Equal(1)) delegateLogger, containerGuid := containerDelegate.DeleteContainerArgsForCall(0) Expect(containerGuid).To(Equal(container.Guid)) Expect(delegateLogger.SessionName()).To(Equal(expectedSessionName)) }) It("does not try to run the container", func() { Expect(containerDelegate.RunContainerCallCount()).To(Equal(0)) }) }) Context("when claiming fails for an unknown reason", func() { BeforeEach(func() { bbsClient.ClaimActualLRPReturns(errors.New("boom")) }) It("does not delete the container", func() {
) BeforeEach(func() { etcdRunner.ResetAllBut(etcddb.VersionKey) containerDelegate = new(fake_internal.FakeContainerDelegate) processor = internal.NewTaskProcessor(bbsClient, containerDelegate, localCellID) containerDelegate.DeleteContainerReturns(true) containerDelegate.StopContainerReturns(true) containerDelegate.RunContainerReturns(true) }) itDeletesTheContainer := func(logger *lagertest.TestLogger) { It("deletes the container", func() { Expect(containerDelegate.DeleteContainerCallCount()).To(Equal(1)) _, containerGuid := containerDelegate.DeleteContainerArgsForCall(0) Expect(containerGuid).To(Equal(taskGuid)) }) } itCompletesTheTaskWithFailure := func(reason string) func(*lagertest.TestLogger) { return func(logger *lagertest.TestLogger) { It("completes the task with failure", func() { task, err := bbsClient.TaskByGuid(taskGuid) Expect(err).NotTo(HaveOccurred()) Expect(task.State).To(Equal(models.Task_Completed)) Expect(task.Failed).To(BeTrue()) Expect(task.FailureReason).To(Equal(reason)) }) }