func (suite *SchedulerTestSuite) TestSchdulerDriverLaunchTasks() { driver := newTestSchedulerDriver(suite.T(), driverConfigMessenger(NewMockScheduler(), suite.framework, suite.master, nil, mockedMessenger())) go func() { driver.Run() }() <-driver.started driver.setConnected(true) // simulated suite.True(driver.Running()) task := util.NewTaskInfo( "simple-task", util.NewTaskID("simpe-task-1"), util.NewSlaveID("slave-1"), []*mesos.Resource{util.NewScalarResource("mem", 400)}, ) task.Command = util.NewCommandInfo("pwd") tasks := []*mesos.TaskInfo{task} stat, err := driver.LaunchTasks( []*mesos.OfferID{{}}, tasks, &mesos.Filters{}, ) suite.NoError(err) suite.Equal(mesos.Status_DRIVER_RUNNING, stat) }
func TestExecutorDriverRunTaskEvent(t *testing.T) { setTestEnv(t) ch := make(chan bool, 2) // Mock Slave process to respond to registration event. server := testutil.NewMockSlaveHttpServer(t, func(rsp http.ResponseWriter, req *http.Request) { reqPath, err := url.QueryUnescape(req.URL.String()) assert.NoError(t, err) log.Infoln("RCVD request", reqPath) rsp.WriteHeader(http.StatusAccepted) }) defer server.Close() exec := newTestExecutor(t) exec.ch = ch exec.t = t // start driver := newIntegrationTestDriver(t, exec) stat, err := driver.Start() assert.NoError(t, err) assert.Equal(t, mesos.Status_DRIVER_RUNNING, stat) driver.setConnected(true) defer driver.Stop() // send runtask event to driver pbMsg := &mesos.RunTaskMessage{ FrameworkId: util.NewFrameworkID(frameworkID), Framework: util.NewFrameworkInfo( "test", "test-framework-001", util.NewFrameworkID(frameworkID), ), Pid: proto.String(server.PID.String()), Task: util.NewTaskInfo( "test-task", util.NewTaskID("test-task-001"), util.NewSlaveID(slaveID), []*mesos.Resource{ util.NewScalarResource("mem", 112), util.NewScalarResource("cpus", 2), }, ), } c := testutil.NewMockMesosClient(t, server.PID) c.SendMessage(driver.self, pbMsg) select { case <-ch: case <-time.After(time.Second * 2): log.Errorf("Tired of waiting...") } }
func (suite *SchedulerTestSuite) TestSchdulerDriverKillTask() { driver := newTestSchedulerDriver(suite.T(), driverConfigMessenger(NewMockScheduler(), suite.framework, suite.master, nil, mockedMessenger())) go func() { driver.Run() }() <-driver.started driver.setConnected(true) // simulated suite.True(driver.Running()) stat, err := driver.KillTask(util.NewTaskID("test-task-1")) suite.NoError(err) suite.Equal(mesos.Status_DRIVER_RUNNING, stat) }
func (suite *SchedulerTestSuite) TestSchdulerDriverLaunchTasksWithError() { sched := NewMockScheduler() sched.On("StatusUpdate").Return(nil) sched.On("Error").Return() msgr := mockedMessenger() driver := newTestSchedulerDriver(suite.T(), driverConfigMessenger(sched, suite.framework, suite.master, nil, msgr)) driver.dispatch = func(_ context.Context, _ *upid.UPID, _ proto.Message) error { return fmt.Errorf("Unable to send message") } go func() { driver.Run() }() <-driver.started driver.setConnected(true) // simulated suite.True(driver.Running()) // setup an offer offer := util.NewOffer( util.NewOfferID("test-offer-001"), suite.framework.Id, util.NewSlaveID("test-slave-001"), "test-slave(1)@localhost:5050", ) pid, err := upid.Parse("test-slave(1)@localhost:5050") suite.NoError(err) driver.cache.putOffer(offer, pid) // launch task task := util.NewTaskInfo( "simple-task", util.NewTaskID("simpe-task-1"), util.NewSlaveID("test-slave-001"), []*mesos.Resource{util.NewScalarResource("mem", 400)}, ) task.Command = util.NewCommandInfo("pwd") task.Executor = util.NewExecutorInfo(util.NewExecutorID("test-exec"), task.Command) tasks := []*mesos.TaskInfo{task} stat, err := driver.LaunchTasks( []*mesos.OfferID{offer.Id}, tasks, &mesos.Filters{}, ) suite.Equal(mesos.Status_DRIVER_RUNNING, stat) suite.Error(err) }
func (suite *SchedulerTestSuite) TestSchdulerDriverReconcileTasks() { driver := newTestSchedulerDriver(suite.T(), driverConfigMessenger(NewMockScheduler(), suite.framework, suite.master, nil, mockedMessenger())) driver.Start() driver.setConnected(true) // simulated suite.Equal(mesos.Status_DRIVER_RUNNING, driver.Status()) stat, err := driver.ReconcileTasks( []*mesos.TaskStatus{ util.NewTaskStatus(util.NewTaskID("test-task-001"), mesos.TaskState_TASK_FINISHED), }, ) suite.NoError(err) suite.Equal(mesos.Status_DRIVER_RUNNING, stat) }
func TestExecutorDriverSendStatusUpdateStaging(t *testing.T) { driver, _, _ := createTestExecutorDriver(t) stat, err := driver.Start() assert.NoError(t, err) assert.Equal(t, mesosproto.Status_DRIVER_RUNNING, stat) driver.setConnected(true) taskStatus := util.NewTaskStatus( util.NewTaskID("test-task-001"), mesosproto.TaskState_TASK_STAGING, ) stat, err = driver.SendStatusUpdate(taskStatus) assert.Error(t, err) assert.Equal(t, mesosproto.Status_DRIVER_ABORTED, stat) }
func TestStatusUpdateAckRace_Issue103(t *testing.T) { driver, _, _ := createTestExecutorDriver(t) _, err := driver.Start() assert.NoError(t, err) msg := &mesosproto.StatusUpdateAcknowledgementMessage{} go func() { driver.lock.Lock() defer driver.lock.Unlock() driver.statusUpdateAcknowledgement(nil, msg) }() taskStatus := util.NewTaskStatus( util.NewTaskID("test-task-001"), mesosproto.TaskState_TASK_STAGING, ) driver.SendStatusUpdate(taskStatus) }
func TestExecutorDriverStatusUpdateAcknowledgement(t *testing.T) { setTestEnv(t) ch := make(chan bool, 2) // Mock Slave process to respond to registration event. server := testutil.NewMockSlaveHttpServer(t, func(rsp http.ResponseWriter, req *http.Request) { reqPath, err := url.QueryUnescape(req.URL.String()) assert.NoError(t, err) log.Infoln("RCVD request", reqPath) rsp.WriteHeader(http.StatusAccepted) }) defer server.Close() exec := newTestExecutor(t) exec.ch = ch exec.t = t // start driver := newIntegrationTestDriver(t, exec) stat, err := driver.Start() assert.NoError(t, err) assert.Equal(t, mesos.Status_DRIVER_RUNNING, stat) driver.setConnected(true) defer driver.Stop() // send ACK from server pbMsg := &mesos.StatusUpdateAcknowledgementMessage{ SlaveId: util.NewSlaveID(slaveID), FrameworkId: util.NewFrameworkID(frameworkID), TaskId: util.NewTaskID("test-task-001"), Uuid: []byte(uuid.NewRandom().String()), } c := testutil.NewMockMesosClient(t, server.PID) c.SendMessage(driver.self, pbMsg) <-time.After(time.Second * 1) }
func (exec *testExecutor) KillTask(driver ExecutorDriver, taskid *mesos.TaskID) { log.Infoln("Exec.KillTask() called.") assert.NotNil(exec.t, taskid) assert.True(exec.t, util.NewTaskID("test-task-001").Equal(taskid)) exec.ch <- true }
func (exec *testExecutor) LaunchTask(driver ExecutorDriver, taskinfo *mesos.TaskInfo) { log.Infoln("Exec.LaunchTask() called.") assert.NotNil(exec.t, taskinfo) assert.True(exec.t, util.NewTaskID("test-task-001").Equal(taskinfo.TaskId)) exec.ch <- true }