Track previous node id correctly, plus unit test

This commit is contained in:
Preetha Appan
2018-01-24 09:33:55 -06:00
parent a2cdb5d6c0
commit 765679f7c9
2 changed files with 12 additions and 1 deletions

View File

@@ -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}
}

View File

@@ -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