It("unclaims and auctions the actual lrps with missing cells", func() { Eventually(fakeLRPDB.UnclaimActualLRPCallCount).Should(Equal(2)) unclaimedKeys := []*models.ActualLRPKey{} for i := 0; i < fakeLRPDB.UnclaimActualLRPCallCount(); i++ { _, key := fakeLRPDB.UnclaimActualLRPArgsForCall(i) unclaimedKeys = append(unclaimedKeys, key) } Expect(unclaimedKeys).To(ContainElement(&unclaimingActualLRP1.ActualLRPKey)) Expect(unclaimedKeys).To(ContainElement(&unclaimingActualLRP2.ActualLRPKey)) Eventually(actualHub.EmitCallCount).Should(Equal(2)) changeEvents := []*models.ActualLRPChangedEvent{} for i := 0; i < actualHub.EmitCallCount(); i++ { event := actualHub.EmitArgsForCall(i) if changeEvent, ok := event.(*models.ActualLRPChangedEvent); ok { changeEvents = append(changeEvents, changeEvent) } } group1 := &models.ActualLRPGroup{Instance: unclaimingActualLRP1} group2 := &models.ActualLRPGroup{Instance: unclaimingActualLRP2} Expect(changeEvents).To(ContainElement(models.NewActualLRPChangedEvent(group1, group1))) Expect(changeEvents).To(ContainElement(models.NewActualLRPChangedEvent(group2, group2))) }) Context("when the DB returns an unrecoverable error", func() { BeforeEach(func() { fakeLRPDB.UnclaimActualLRPReturns(nil, nil, models.NewUnrecoverableError(nil)) })
Expect(err).NotTo(HaveOccurred()) Expect(response.Error).To(BeNil()) }) It("claims the actual lrp by process guid and index", func() { Expect(fakeActualLRPDB.ClaimActualLRPCallCount()).To(Equal(1)) _, actualProcessGuid, actualIndex, actualInstanceKey := fakeActualLRPDB.ClaimActualLRPArgsForCall(0) Expect(actualProcessGuid).To(Equal(processGuid)) Expect(actualIndex).To(BeEquivalentTo(index)) Expect(*actualInstanceKey).To(Equal(instanceKey)) }) It("emits a change event to the hub", func() { Eventually(actualHub.EmitCallCount).Should(Equal(1)) event := actualHub.EmitArgsForCall(0) changedEvent, ok := event.(*models.ActualLRPChangedEvent) Expect(ok).To(BeTrue()) Expect(changedEvent.Before).To(Equal(&models.ActualLRPGroup{Instance: &actualLRP})) Expect(changedEvent.After).To(Equal(&models.ActualLRPGroup{Instance: &afterActualLRP})) }) Context("when the actual lrp did not actually change", func() { BeforeEach(func() { fakeActualLRPDB.ClaimActualLRPReturns( &models.ActualLRPGroup{Instance: &afterActualLRP}, &models.ActualLRPGroup{Instance: &afterActualLRP}, nil, ) })
It("creates desired lrp", func() { Expect(fakeDesiredLRPDB.DesireLRPCallCount()).To(Equal(1)) _, actualDesiredLRP := fakeDesiredLRPDB.DesireLRPArgsForCall(0) Expect(actualDesiredLRP).To(Equal(desiredLRP)) Expect(responseRecorder.Code).To(Equal(http.StatusOK)) response := models.DesiredLRPLifecycleResponse{} err := response.Unmarshal(responseRecorder.Body.Bytes()) Expect(err).NotTo(HaveOccurred()) Expect(response.Error).To(BeNil()) }) It("emits a create event to the hub", func() { Eventually(desiredHub.EmitCallCount).Should(Equal(1)) event := desiredHub.EmitArgsForCall(0) createEvent, ok := event.(*models.DesiredLRPCreatedEvent) Expect(ok).To(BeTrue()) Expect(createEvent.DesiredLrp).To(Equal(desiredLRP)) }) It("creates and emits an event for one ActualLRP per index", func() { Expect(fakeActualLRPDB.CreateUnclaimedActualLRPCallCount()).To(Equal(5)) Eventually(actualHub.EmitCallCount).Should(Equal(5)) expectedLRPKeys := []*models.ActualLRPKey{} for i := 0; i < 5; i++ { expectedLRPKeys = append(expectedLRPKeys, &models.ActualLRPKey{ ProcessGuid: desiredLRP.ProcessGuid, Domain: desiredLRP.Domain,
BeforeEach(func() { fakeEvacuationDB.RemoveEvacuatingActualLRPReturns(nil) }) It("removeEvacuatings the actual lrp by process guid and index", func() { Expect(responseRecorder.Code).To(Equal(http.StatusOK)) Expect(fakeEvacuationDB.RemoveEvacuatingActualLRPCallCount()).To(Equal(1)) _, actualKey, actualInstanceKey := fakeEvacuationDB.RemoveEvacuatingActualLRPArgsForCall(0) Expect(*actualKey).To(Equal(key)) Expect(*actualInstanceKey).To(Equal(instanceKey)) }) It("emits events to the hub", func() { Eventually(actualHub.EmitCallCount).Should(Equal(1)) event := actualHub.EmitArgsForCall(0) removeEvent, ok := event.(*models.ActualLRPRemovedEvent) Expect(ok).To(BeTrue()) Expect(removeEvent.ActualLrpGroup).To(Equal(&models.ActualLRPGroup{Evacuating: actual})) }) }) Context("when the request is invalid", func() { BeforeEach(func() { requestBody = &models.RemoveEvacuatingActualLRPRequest{} }) It("responds with an error", func() { Expect(responseRecorder.Code).To(Equal(http.StatusOK)) var response models.RemoveEvacuatingActualLRPResponse