JustBeforeEach(func() { handler.Update(responseRecorder, req) }) It("retries up to one time", func() { Eventually(fakeLegacyBBS.UpdateDesiredLRPCallCount).Should(Equal(2)) Consistently(fakeLegacyBBS.UpdateDesiredLRPCallCount).Should(Equal(2)) }) Context("when the second attempt succeeds", func() { BeforeEach(func() { fakeLegacyBBS.UpdateDesiredLRPStub = func(logger lager.Logger, processGuid string, update oldmodels.DesiredLRPUpdate) error { if fakeLegacyBBS.UpdateDesiredLRPCallCount() == 1 { return bbserrors.ErrStoreComparisonFailed } else if fakeLegacyBBS.UpdateDesiredLRPCallCount() == 2 { return nil } else { return errors.New("We shouldn't call this function more than twice") } } }) It("returns a 204 No Content", func() { Eventually(fakeLegacyBBS.UpdateDesiredLRPCallCount).Should(Equal(2)) Expect(responseRecorder.Code).To(Equal(http.StatusNoContent)) Consistently(fakeLegacyBBS.UpdateDesiredLRPCallCount).Should(Equal(2)) }) }) Context("when the second attempt fails", func() { It("returns a 500 Internal Server Error", func() {