func matchTaskAuction(offerAggregates [][]*mesos.Offer, taskAuction *auctiontypes.TaskAuction) (int, []*mesos.Offer) { taskAuction.Attempts++ for i, offers := range offerAggregates { if getOffersMem(offers) > float64(taskAuction.MemoryMB) && getOffersCpu(offers) > taskCpuAllocation && getOffersDisk(offers) > float64(taskAuction.DiskMB) { taskAuction.Winner = offers[0].SlaveId.GetValue() taskAuction.WaitDuration = time.Now().Sub(taskAuction.QueueTime) offers[0].Resources = append(offers[0].Resources, util.NewScalarResource("mem", float64(-taskAuction.MemoryMB)), util.NewScalarResource("cpu", -taskCpuAllocation), util.NewScalarResource("disk", float64(-taskAuction.DiskMB))) return i, offers } } taskAuction.PlacementError = rep.ErrorInsufficientResources.Error() return -1, nil }
results = s.Schedule(auctiontypes.AuctionRequest{Tasks: []auctiontypes.TaskAuction{taskAuction}}) }) It("picks the best cell for the job", func() { Expect(clients["A-cell"].PerformCallCount()).To(Equal(0)) Expect(clients["B-cell"].PerformCallCount()).To(Equal(0)) Expect(clients["C-cell"].PerformCallCount()).To(Equal(1)) startsToC := clients["C-cell"].PerformArgsForCall(0).Tasks Expect(startsToC).To(ConsistOf(taskAuction.Task)) }) It("marks the start auction as succeeded", func() { setTaskWinner("C-cell", &taskAuction) taskAuction.WaitDuration = time.Minute Expect(results.SuccessfulTasks).To(ConsistOf(taskAuction)) Expect(results.FailedTasks).To(BeEmpty()) }) }) }) }) Context("when it picks a winner", func() { BeforeEach(func() { s := auctionrunner.NewScheduler(workPool, zones, clock, logger) results = s.Schedule(auctiontypes.AuctionRequest{Tasks: []auctiontypes.TaskAuction{taskAuction}}) }) It("picks the best cell for the job", func() { Expect(clients["A-cell"].PerformCallCount()).To(Equal(0))