diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index 9a6b57903..5830c5d11 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -531,7 +531,7 @@ func updateRescheduleTracker(alloc *structs.Allocation, prev *structs.Allocation rescheduleEvents = append(rescheduleEvents, reschedEvent.Copy()) } } - rescheduleEvent := structs.NewRescheduleEvent(time.Now().UTC().UnixNano(), prev.ID, alloc.NodeID) + rescheduleEvent := structs.NewRescheduleEvent(time.Now().UTC().UnixNano(), prev.ID, prev.NodeID) rescheduleEvents = append(rescheduleEvents, rescheduleEvent) alloc.RescheduleTracker = &structs.RescheduleTracker{Events: rescheduleEvents} } diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index f837200c0..9abe394d4 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -2867,6 +2867,9 @@ func TestServiceSched_Reschedule_Multiple(t *testing.T) { expectedNumAllocs := 3 expectedNumReschedTrackers := 1 + failedAllocId := allocs[1].ID + failedNodeID := allocs[1].NodeID + assert := assert.New(t) for i := 0; i < maxRestartAttempts; i++ { // Process the evaluation @@ -2897,9 +2900,17 @@ func TestServiceSched_Reschedule_Multiple(t *testing.T) { newAlloc := pendingAllocs[0] assert.Equal(expectedNumReschedTrackers, len(newAlloc.RescheduleTracker.Events)) + // Verify the previous NodeID in the most recent reschedule event + reschedEvents := newAlloc.RescheduleTracker.Events + assert.Equal(failedAllocId, reschedEvents[len(reschedEvents)-1].PrevAllocID) + assert.Equal(failedNodeID, reschedEvents[len(reschedEvents)-1].PrevNodeID) + // Mark this alloc as failed again newAlloc.ClientStatus = structs.AllocClientStatusFailed + failedAllocId = newAlloc.ID + failedNodeID = newAlloc.NodeID + noErr(t, h.State.UpsertAllocs(h.NextIndex(), []*structs.Allocation{newAlloc})) // Create another mock evaluation