Ejemplo n.º 1
0
		getTaskStatus := func(state string) task_examiner.TaskInfo {
			return task_examiner.TaskInfo{
				TaskGuid: "task-guid-1",
				State:    state,
			}
		}

		Context("when the receptor returns errors", func() {

			It("returns error when not able to delete the task", func() {
				fakeTaskExaminer.TaskStatusReturns(getTaskStatus(receptor.TaskStateCompleted), nil)
				fakeReceptorClient.DeleteTaskReturns(errors.New("task in unknown state"))

				errChan := make(chan error)
				go func() {
					errChan <- taskRunner.DeleteTask("task-guid-1")
				}()
				Eventually(fakeClock.WatcherCount).Should(Equal(2))
				fakeClock.IncrementBySeconds(1)
				Expect(<-errChan).To(MatchError("task in unknown state"))
			})

			It("returns error when timeout to delete the task", func() {
				fakeTaskExaminer.TaskStatusReturns(getTaskStatus(receptor.TaskStateRunning), nil)
				errChan := make(chan error)
				go func() {
					errChan <- taskRunner.DeleteTask("task-guid-1")
				}()

				Eventually(fakeClock.WatcherCount).Should(Equal(2))
				fakeClock.IncrementBySeconds(31)
Ejemplo n.º 2
0
		})
	})

	Describe("Delete Task", func() {
		getTaskStatus := func(state string) task_examiner.TaskInfo {
			return task_examiner.TaskInfo{
				TaskGuid: "task-guid-1",
				State:    state,
			}
		}

		It("delete task when task in COMPLETED state", func() {
			fakeTaskExaminer.TaskStatusReturns(getTaskStatus(receptor.TaskStateCompleted), nil)

			err := taskRunner.DeleteTask("task-guid-1")
			Expect(err).ToNot(HaveOccurred())
		})

		It("return error when task is not in COMPLETED state", func() {
			fakeTaskExaminer.TaskStatusReturns(getTaskStatus(receptor.TaskStatePending), nil)

			err := taskRunner.DeleteTask("task-guid-1")
			Expect(err).To(MatchError("task-guid-1 is not in COMPLETED state"))
		})

		Context("when the receptor returns errors", func() {
			It("bubbles up the error from task_examiner.TaskStatus", func() {
				fakeTaskExaminer.TaskStatusReturns(task_examiner.TaskInfo{}, errors.New("Task not found"))

				err := taskRunner.DeleteTask("task-guid-1")