diff --git a/nomad/plan_queue.go b/nomad/plan_queue.go index ab2426bf0..69fee9549 100644 --- a/nomad/plan_queue.go +++ b/nomad/plan_queue.go @@ -50,9 +50,10 @@ func NewPlanQueue() (*PlanQueue, error) { // pendingPlan is used to wrap a plan that is enqueued // so that we can re-use it as a future. type pendingPlan struct { - plan *structs.Plan - result *structs.PlanResult - errCh chan error + plan *structs.Plan + enqueueTime time.Time + result *structs.PlanResult + errCh chan error } // Wait is used to block for the plan result or potential error @@ -95,8 +96,9 @@ func (q *PlanQueue) Enqueue(plan *structs.Plan) (PlanFuture, error) { // Wrap the pending plan pending := &pendingPlan{ - plan: plan, - errCh: make(chan error, 1), + plan: plan, + enqueueTime: time.Now(), + errCh: make(chan error, 1), } // Push onto the heap @@ -207,13 +209,13 @@ func (p PendingPlans) Len() int { // Less is for the sorting interface. We flip the check // so that the "min" in the min-heap is the element with the -// highest priority. For the same priority, we use the create -// index of the evaluation to give a FIFO ordering. +// highest priority. For the same priority, we use the enqueue +// time of the evaluation to give a FIFO ordering. func (p PendingPlans) Less(i, j int) bool { if p[i].plan.Priority != p[j].plan.Priority { return !(p[i].plan.Priority < p[j].plan.Priority) } - return p[i].plan.EvalCreateIndex < p[j].plan.EvalCreateIndex + return p[i].enqueueTime.Before(p[j].enqueueTime) } // Swap is for the sorting interface diff --git a/nomad/plan_queue_test.go b/nomad/plan_queue_test.go index e684ccbd7..0e4a26a82 100644 --- a/nomad/plan_queue_test.go +++ b/nomad/plan_queue_test.go @@ -17,8 +17,7 @@ func testPlanQueue(t *testing.T) *PlanQueue { func mockPlan() *structs.Plan { return &structs.Plan{ - Priority: 50, - EvalCreateIndex: 1000, + Priority: 50, } } @@ -166,15 +165,16 @@ func TestPlanQueue_Dequeue_FIFO(t *testing.T) { pq.SetEnabled(true) NUM := 100 + plans := make([]*structs.Plan, NUM) for i := 0; i < NUM; i++ { plan := mockPlan() - plan.EvalCreateIndex = uint64(i) pq.Enqueue(plan) + plans[i] = plan } for i := 0; i < NUM; i++ { out1, _ := pq.Dequeue(time.Second) - if out1.plan.EvalCreateIndex != uint64(i) { + if out1.plan != plans[i] { t.Fatalf("bad: %d %#v", i, out1) } }