Expect(returnedTask.FailureReason).To(ContainSubstring("time limit")) }) It("bumps the compare-and-swap counter", func() { Expect(sender.GetCounter("ConvergenceTasksKicked")).To(Equal(uint64(2))) }) It("logs an error", func() { Expect(logger.TestSink.LogMessages()).To(ContainElement("test.converge-tasks.failed-to-start-in-time")) }) }) }) Context("when a Task is running", func() { BeforeEach(func() { err := etcdDB.DesireTask(logger, model_helpers.NewValidTaskDefinition(), taskGuid, domain) Expect(err).NotTo(HaveOccurred()) _, err = etcdDB.StartTask(logger, taskGuid, "cell-id") Expect(err).NotTo(HaveOccurred()) }) It("emits a running metric", func() { Expect(sender.GetValue("TasksRunning").Value).To(Equal(float64(1))) }) Context("when the associated cell is present", func() { BeforeEach(func() { cellPresence := models.NewCellPresence("cell-id", "1.2.3.4", "the-zone", models.NewCellCapacity(128, 1024, 3), []string{}, []string{}) registerCell(cellPresence) })
func exampleTaskDefinition() *models.TaskDefinition { taskDef := model_helpers.NewValidTaskDefinition() taskDef.RootFs = linuxRootFSURL taskDef.Action = models.WrapAction(dummyAction) return taskDef }
}) Describe("DesireTask", func() { It("adds the desired task", func() { expectedTask := model_helpers.NewValidTask("task-1") err := client.DesireTask(logger, expectedTask.TaskGuid, expectedTask.Domain, expectedTask.TaskDefinition) Expect(err).NotTo(HaveOccurred()) task, err := client.TaskByGuid(logger, expectedTask.TaskGuid) Expect(err).NotTo(HaveOccurred()) Expect(task).To(MatchTask(expectedTask)) }) }) Describe("Task Lifecycle", func() { var taskDef = model_helpers.NewValidTaskDefinition() const taskGuid = "task-1" const cellId = "cell-1" BeforeEach(func() { err := client.DesireTask(logger, taskGuid, "test", taskDef) Expect(err).NotTo(HaveOccurred()) }) Describe("StartTask", func() { It("changes the task state from pending to running", func() { task, err := client.TaskByGuid(logger, taskGuid) Expect(err).NotTo(HaveOccurred()) Expect(task.State).To(Equal(models.Task_Pending)) _, err = client.StartTask(logger, taskGuid, cellId)
Expect(err).NotTo(HaveOccurred()) Expect(response.Error).To(Equal(models.ErrUnknownError)) }) }) }) Describe("DesireTask", func() { var ( taskGuid = "task-guid" domain = "domain" taskDef *models.TaskDefinition ) BeforeEach(func() { taskDef = model_helpers.NewValidTaskDefinition() requestBody = &models.DesireTaskRequest{ TaskGuid: taskGuid, Domain: domain, TaskDefinition: taskDef, } }) JustBeforeEach(func() { request := newTestRequest(requestBody) handler.DesireTask(responseRecorder, request) }) Context("when the desire is successful", func() { It("desires the task with the requested definitions", func() { Expect(fakeTaskDB.DesireTaskCallCount()).To(Equal(1))