Exemplo n.º 1
0
		controller = &fake_controllers.FakeTaskController{}
		handler = handlers.NewTaskHandler(controller, exitCh)
	})

	Describe("DesireTask", func() {
		var (
			taskGuid   = "task-guid"
			domain     = "domain"
			oldTaskDef *models.TaskDefinition
		)

		BeforeEach(func() {
			config, err := json.Marshal(map[string]string{"foo": "bar"})
			Expect(err).NotTo(HaveOccurred())

			oldTaskDef = model_helpers.NewValidTaskDefinition()
			oldTaskDef.VolumeMounts = []*models.VolumeMount{{
				Driver:             "my-driver",
				ContainerDir:       "/mnt/mypath",
				DeprecatedMode:     models.DeprecatedBindMountMode_RO,
				DeprecatedConfig:   config,
				DeprecatedVolumeId: "my-volume",
			}}

			requestBody = &models.DesireTaskRequest{
				TaskGuid:       taskGuid,
				Domain:         domain,
				TaskDefinition: oldTaskDef,
			}

		})
Exemplo n.º 2
0
				Expect(err).NotTo(HaveOccurred())
				Expect(task).To(BeEquivalentTo(beforeTask))
			})
		})
	})

	Describe("CancelTask", func() {
		var (
			taskGuid, taskDomain string
			taskDefinition       *models.TaskDefinition
		)

		BeforeEach(func() {
			taskGuid = "the-task-guid"
			taskDomain = "the-task-domain"
			taskDefinition = model_helpers.NewValidTaskDefinition()
		})

		Context("when the task is pending", func() {
			BeforeEach(func() {
				err := sqlDB.DesireTask(logger, taskDefinition, taskGuid, taskDomain)
				Expect(err).NotTo(HaveOccurred())
			})

			It("cancels the task", func() {
				fakeClock.Increment(time.Second)
				now := fakeClock.Now().UnixNano()

				task, cellID, err := sqlDB.CancelTask(logger, taskGuid)
				Expect(err).NotTo(HaveOccurred())
Exemplo n.º 3
0
					Expect(err).NotTo(HaveOccurred())
					Expect(returnedTask.State).To(Equal(models.Task_Completed))

					Expect(returnedTask.Failed).To(Equal(true))
					Expect(returnedTask.FailureReason).To(ContainSubstring("time limit"))
				})

				It("bumps the compare-and-swap counter", func() {
					Expect(sender.GetCounter("ConvergenceTasksKicked")).To(Equal(uint64(2)))
				})
			})
		})

		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",
Exemplo n.º 4
0
			It("provides relevant error information", func() {
				Expect(err).To(MatchError("kaboom"))
			})
		})
	})

	Describe("DesireTask", func() {
		var (
			taskGuid = "task-guid"
			domain   = "domain"
			taskDef  *models.TaskDefinition
			err      error
		)

		BeforeEach(func() {
			taskDef = model_helpers.NewValidTaskDefinition()
		})

		JustBeforeEach(func() {
			err = controller.DesireTask(logger, taskDef, taskGuid, domain)
		})

		Context("when the desire is successful", func() {
			It("desires the task with the requested definitions", func() {
				Expect(err).NotTo(HaveOccurred())

				Expect(fakeTaskDB.DesireTaskCallCount()).To(Equal(1))
				_, actualTaskDef, actualTaskGuid, actualDomain := fakeTaskDB.DesireTaskArgsForCall(0)
				Expect(actualTaskDef).To(Equal(taskDef))
				Expect(actualTaskGuid).To(Equal(taskGuid))
				Expect(actualDomain).To(Equal(domain))
Exemplo n.º 5
0
				It("returns a validation error", func() {
					Expect(request.Validate()).To(ConsistOf(models.ErrInvalidField{"task_guid"}))
				})
			})
		})
	})

	Describe("DesireTaskRequest", func() {
		Describe("Validate", func() {
			var request models.DesireTaskRequest

			BeforeEach(func() {
				request = models.DesireTaskRequest{
					TaskGuid:       "t-guid",
					Domain:         "domain",
					TaskDefinition: model_helpers.NewValidTaskDefinition(),
				}
			})

			Context("when valid", func() {
				It("returns nil", func() {
					Expect(request.Validate()).To(BeNil())
				})
			})

			Context("when the TaskGuid is blank", func() {
				BeforeEach(func() {
					request.TaskGuid = ""
				})

				It("returns a validation error", func() {