Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions controllers/actual_lrp_lifecycle_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,17 @@ func (h *ActualLRPLifecycleController) RetireActualLRP(ctx context.Context, logg
go eventCalculator.EmitEvents(trace.RequestIdFromContext(ctx), lrps, newLRPs)
}()

removeLRP := func() error {
err = h.db.RemoveActualLRP(ctx, logger, lrp.ProcessGuid, lrp.Index, &lrp.ActualLRPInstanceKey)
if err == nil {
newLRPs = eventCalculator.RecordChange(lrp, nil, lrps)
}
return err
}
recordChange := func() {
newLRPs = eventCalculator.RecordChange(lrp, nil, lrps)
}

removeLRP := func() error {
err = h.db.RemoveActualLRP(ctx, logger, lrp.ProcessGuid, lrp.Index, &lrp.ActualLRPInstanceKey)
if err == nil {
recordChange()
}
return err
}

for retryCount := 0; retryCount < models.RetireActualLRPRetryAttempts; retryCount++ {
switch lrp.State {
Expand All @@ -312,6 +316,7 @@ func (h *ActualLRPLifecycleController) RetireActualLRP(ctx context.Context, logg
}

var client rep.Client
recordChange()
client, err = h.repClientFactory.CreateClient(cell.RepAddress, cell.RepUrl, trace.RequestIdFromContext(ctx))
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions controllers/actual_lrp_lifecycle_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,15 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() {
Expect(stoppedKey).To(Equal(actualLRPKey))
Expect(stoppedInstanceKey).To(Equal(afterInstanceKey))
})

It("emits a removed event to the hub", func() {
err = controller.RetireActualLRP(ctx, logger, &actualLRPKey)
Eventually(actualHub.EmitCallCount).Should(Equal(1))
event := actualHub.EmitArgsForCall(0)
removedEvent, ok := event.(*models.ActualLRPRemovedEvent)
Expect(ok).To(BeTrue())
Expect(removedEvent.ActualLrpGroup).To(Equal(actualLRP.ToActualLRPGroup()))
})

Context("when the rep announces a rep url", func() {
BeforeEach(func() {
Expand Down