示例#1
0
func TestReconcile(t *testing.T) {
	db := eremetic.NewDefaultTaskDB()

	maxReconciliationDelay = 1

	Convey("ReconcileTasks", t, func() {
		Convey("Finishes when there are no tasks", func() {
			driver := mock.NewMesosScheduler()
			r := reconcileTasks(driver, db)

			select {
			case <-r.done:
			}

			So(driver.ReconcileTasksFnInvoked, ShouldBeFalse)
		})

		Convey("Sends reconcile request", func() {
			driver := mock.NewMesosScheduler()
			driver.ReconcileTasksFn = func(ts []*mesosproto.TaskStatus) (mesosproto.Status, error) {
				t, err := db.ReadTask("1234")
				if err != nil {
					return mesosproto.Status_DRIVER_RUNNING, err
				}
				t.UpdateStatus(eremetic.Status{
					Status: eremetic.TaskRunning,
					Time:   time.Now().Unix() + 1,
				})
				db.PutTask(&t)

				return mesosproto.Status_DRIVER_RUNNING, nil
			}

			db.PutTask(&eremetic.Task{
				ID: "1234",
				Status: []eremetic.Status{
					eremetic.Status{
						Status: eremetic.TaskStaging,
						Time:   time.Now().Unix(),
					},
				},
			})

			r := reconcileTasks(driver, db)

			select {
			case <-r.done:
			}

			So(driver.ReconcileTasksFnInvoked, ShouldBeTrue)
		})

		Convey("Cancel reconciliation", func() {
			driver := mock.NewMesosScheduler()

			db.PutTask(&eremetic.Task{
				ID: "1234",
				Status: []eremetic.Status{
					eremetic.Status{
						Status: eremetic.TaskStaging,
						Time:   time.Now().Unix(),
					},
				},
			})

			r := reconcileTasks(driver, db)
			r.Cancel()

			select {
			case <-r.done:
			}

			So(driver.ReconcileTasksFnInvoked, ShouldBeFalse)
		})
	})
}
示例#2
0
func TestReconcile(t *testing.T) {
	dir, _ := os.Getwd()
	database.NewDB(fmt.Sprintf("%s/../db/test.db", dir))
	database.Clean()
	defer database.Close()

	maxReconciliationDelay = 1

	Convey("ReconcileTasks", t, func() {
		Convey("Finishes when there are no tasks", func() {
			driver := NewMockScheduler()
			r := ReconcileTasks(driver)

			select {
			case <-r.done:
			}

			So(driver.AssertNotCalled(t, "ReconcileTasks"), ShouldBeTrue)
		})

		Convey("Sends reconcile request", func() {
			driver := NewMockScheduler()
			driver.On("ReconcileTasks").Run(func(mock.Arguments) {
				t, err := database.ReadTask("1234")
				if err != nil {
					panic("mock error")
				}
				t.UpdateStatus(types.Status{
					Status: mesos.TaskState_TASK_RUNNING.String(),
					Time:   time.Now().Unix() + 1,
				})
				database.PutTask(&t)
			}).Once()

			database.PutTask(&types.EremeticTask{
				ID: "1234",
				Status: []types.Status{
					types.Status{
						Status: mesos.TaskState_TASK_STAGING.String(),
						Time:   time.Now().Unix(),
					},
				},
			})

			r := ReconcileTasks(driver)

			select {
			case <-r.done:
			}

			So(driver.AssertCalled(t, "ReconcileTasks"), ShouldBeTrue)
		})

		Convey("Cancel reconciliation", func() {
			driver := NewMockScheduler()

			database.PutTask(&types.EremeticTask{
				ID: "1234",
				Status: []types.Status{
					types.Status{
						Status: mesos.TaskState_TASK_STAGING.String(),
						Time:   time.Now().Unix(),
					},
				},
			})

			r := ReconcileTasks(driver)
			r.Cancel()

			select {
			case <-r.done:
			}

			So(driver.AssertNotCalled(t, "ReconcileTasks"), ShouldBeTrue)
		})
	})
}