func TestSchedCachePutOffer(t *testing.T) {
	cache := newSchedCache()

	offer01 := createTestOffer("01")
	pid01, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)
	cache.putOffer(offer01, pid01)

	offer02 := createTestOffer("02")
	pid02, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)
	cache.putOffer(offer02, pid02)

	assert.Equal(t, len(cache.savedOffers), 2)
	cachedOffer1, ok := cache.savedOffers["test-offer-01"]
	assert.True(t, ok)
	cachedOffer2, ok := cache.savedOffers["test-offer-02"]
	assert.True(t, ok)

	assert.NotNil(t, cachedOffer1.offer)
	assert.Equal(t, "test-offer-01", cachedOffer1.offer.Id.GetValue())
	assert.NotNil(t, cachedOffer2.offer)
	assert.Equal(t, "test-offer-02", cachedOffer2.offer.Id.GetValue())

	assert.NotNil(t, cachedOffer1.slavePid)
	assert.Equal(t, "[email protected]:5050", cachedOffer1.slavePid.String())
	assert.NotNil(t, cachedOffer2.slavePid)
	assert.Equal(t, "[email protected]:5050", cachedOffer2.slavePid.String())

}
func TestSchedCachePutSlavePid(t *testing.T) {
	cache := newSchedCache()

	pid01, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)
	pid02, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)
	pid03, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)

	cache.putSlavePid(util.NewSlaveID("slave01"), pid01)
	cache.putSlavePid(util.NewSlaveID("slave02"), pid02)
	cache.putSlavePid(util.NewSlaveID("slave03"), pid03)

	assert.Equal(t, len(cache.savedSlavePids), 3)
	cachedSlavePid1, ok := cache.savedSlavePids["slave01"]
	assert.True(t, ok)
	cachedSlavePid2, ok := cache.savedSlavePids["slave02"]
	assert.True(t, ok)
	cachedSlavePid3, ok := cache.savedSlavePids["slave03"]
	assert.True(t, ok)

	assert.True(t, cachedSlavePid1.Equal(pid01))
	assert.True(t, cachedSlavePid2.Equal(pid02))
	assert.True(t, cachedSlavePid3.Equal(pid03))
}
func BenchmarkMessengerSendRecvMixedMessage(b *testing.B) {
	globalWG.Add(b.N)
	messages := generateMixedMessages(1000)

	upid1, err := upid.Parse(fmt.Sprintf("mesos1@localhost:%d", getNewPort()))
	assert.NoError(b, err)
	upid2, err := upid.Parse(fmt.Sprintf("mesos2@localhost:%d", getNewPort()))
	assert.NoError(b, err)

	m1 := NewHttp(upid1)
	m2 := NewHttp(upid2)
	assert.NoError(b, m1.Start())
	assert.NoError(b, m2.Start())
	assert.NoError(b, m2.Install(noopHandler, &testmessage.SmallMessage{}))
	assert.NoError(b, m2.Install(noopHandler, &testmessage.MediumMessage{}))
	assert.NoError(b, m2.Install(noopHandler, &testmessage.BigMessage{}))
	assert.NoError(b, m2.Install(noopHandler, &testmessage.LargeMessage{}))

	time.Sleep(time.Second) // Avoid race on upid.
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		m1.Send(context.TODO(), upid2, messages[i%1000])
	}
	globalWG.Wait()
}
func TestTransporterStartAndRcvd(t *testing.T) {
	serverId := "testserver"
	serverPort := getNewPort()
	serverAddr := "127.0.0.1:" + strconv.Itoa(serverPort)
	protoMsg := testmessage.GenerateSmallMessage()
	msgName := getMessageName(protoMsg)
	ctrl := make(chan struct{})

	// setup receiver (server) process
	rcvPid, err := upid.Parse(fmt.Sprintf("%s@%s", serverId, serverAddr))
	assert.NoError(t, err)
	receiver := NewHTTPTransporter(rcvPid, nil)
	receiver.Install(msgName)

	go func() {
		defer close(ctrl)
		msg, err := receiver.Recv()
		assert.Nil(t, err)
		assert.NotNil(t, msg)
		if msg != nil {
			assert.Equal(t, msgName, msg.Name)
		}
	}()

	errch := receiver.Start()
	defer receiver.Stop(false)
	assert.NotNil(t, errch)

	time.Sleep(time.Millisecond * 7) // time to catchup

	// setup sender (client) process
	sndUpid, err := upid.Parse(fmt.Sprintf("mesos1@localhost:%d", getNewPort()))
	assert.NoError(t, err)

	sender := NewHTTPTransporter(sndUpid, nil)
	msg := &Message{
		UPID:         rcvPid,
		Name:         msgName,
		ProtoMessage: protoMsg,
	}
	errch2 := sender.Start()
	defer sender.Stop(false)

	sender.Send(context.TODO(), msg)

	select {
	case <-time.After(time.Second * 5):
		t.Fatalf("Timeout")
	case <-ctrl:
	case err := <-errch:
		if err != nil {
			t.Fatalf(err.Error())
		}
	case err := <-errch2:
		if err != nil {
			t.Fatalf(err.Error())
		}
	}
}
Beispiel #5
0
func getLibprocessFrom(r *http.Request) (*upid.UPID, error) {
	if r.Method != "POST" {
		return nil, fmt.Errorf("Not a POST request")
	}
	if agent, ok := parseLibprocessAgent(r.Header); ok {
		return upid.Parse(agent)
	}
	lf, ok := r.Header["Libprocess-From"]
	if ok {
		// TODO(yifan): Just take the first field for now.
		return upid.Parse(lf[0])
	}
	return nil, fmt.Errorf("Cannot find 'User-Agent' or 'Libprocess-From'")
}
func TestSchedCacheContainsSlavePid(t *testing.T) {
	cache := newSchedCache()

	pid01, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)
	pid02, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)

	cache.putSlavePid(util.NewSlaveID("slave01"), pid01)
	cache.putSlavePid(util.NewSlaveID("slave02"), pid02)

	assert.True(t, cache.containsSlavePid(util.NewSlaveID("slave01")))
	assert.True(t, cache.containsSlavePid(util.NewSlaveID("slave02")))
	assert.False(t, cache.containsSlavePid(util.NewSlaveID("slave05")))
}
Beispiel #7
0
// assumes that address is in host:port format
func (s *Standalone) _fetchPid(ctx context.Context, address string) (*upid.UPID, error) {
	//TODO(jdef) need SSL support
	uri := fmt.Sprintf("http://%s/state", address)
	req, err := http.NewRequest("GET", uri, nil)
	if err != nil {
		return nil, err
	}
	var pid *upid.UPID
	err = s.httpDo(ctx, req, func(res *http.Response, err error) error {
		if err != nil {
			return err
		}
		defer res.Body.Close()
		if res.StatusCode != 200 {
			return fmt.Errorf("HTTP request failed with code %d: %v", res.StatusCode, res.Status)
		}
		blob, err1 := ioutil.ReadAll(res.Body)
		if err1 != nil {
			return err1
		}
		log.V(3).Infof("Got mesos state, content length %v", len(blob))
		type State struct {
			Leader string `json:"leader"` // ex: master(1)@10.22.211.18:5050
		}
		state := &State{}
		err = json.Unmarshal(blob, state)
		if err != nil {
			return err
		}
		pid, err = upid.Parse(state.Leader)
		return err
	})
	return pid, err
}
func TestMutatedHostUPid(t *testing.T) {
	serverId := "testserver"
	// NOTE(tsenart): This static port can cause conflicts if multiple instances
	// of this test run concurrently or else if this port is already bound by
	// another socket.
	serverPort := 12345
	serverHost := "127.0.0.1"
	serverAddr := serverHost + ":" + strconv.Itoa(serverPort)

	// override the upid.Host with this listener IP
	addr := net.ParseIP("0.0.0.0")

	// setup receiver (server) process
	uPid, err := upid.Parse(fmt.Sprintf("%s@%s", serverId, serverAddr))
	assert.NoError(t, err)
	receiver := NewHTTPTransporter(*uPid, addr)

	err = receiver.listen()
	assert.NoError(t, err)

	if receiver.upid.Host != "127.0.0.1" {
		t.Fatalf("reciever.upid.Host was expected to return %s, got %s\n", serverHost, receiver.upid.Host)
	}

	if receiver.upid.Port != strconv.Itoa(serverPort) {
		t.Fatalf("receiver.upid.Port was expected to return %d, got %s\n", serverPort, receiver.upid.Port)
	}
}
func TestMessengerFailToSend(t *testing.T) {
	upid, err := upid.Parse(fmt.Sprintf("mesos1@localhost:%d", getNewPort()))
	assert.NoError(t, err)
	m := NewHttp(upid)
	assert.NoError(t, m.Start())
	assert.Error(t, m.Send(context.TODO(), upid, &testmessage.SmallMessage{}))
}
func TestEmptyHostPortUPid(t *testing.T) {
	serverId := "testserver"
	serverPort := getNewPort()
	serverHost := "127.0.0.1"
	serverAddr := serverHost + ":" + strconv.Itoa(serverPort)

	// setup receiver (server) process
	uPid, err := upid.Parse(fmt.Sprintf("%s@%s", serverId, serverAddr))
	assert.NoError(t, err)

	// Unset upid host and port
	uPid.Host = ""
	uPid.Port = ""

	// override the upid.Host with this listener IP
	addr := net.ParseIP("127.0.0.2")

	receiver := NewHTTPTransporter(uPid, addr)

	err = receiver.listen()
	assert.NoError(t, err)

	// This should be the host that overrides as uPid.Host is empty
	if receiver.upid.Host != "127.0.0.2" {
		t.Fatalf("reciever.upid.Host was expected to return %s, got %s\n", serverHost, receiver.upid.Host)
	}

	// This should end up being a random port, not the server port as uPid
	// port is empty
	if receiver.upid.Port == strconv.Itoa(serverPort) {
		t.Fatalf("receiver.upid.Port was not expected to return %d, got %s\n", serverPort, receiver.upid.Port)
	}
}
func TestSlaveHealthCheckerFailedOnBlockedSlave(t *testing.T) {
	s := newBlockedServer(5)
	ts := httptest.NewUnstartedServer(s)
	ts.Start()
	defer ts.Close()
	defer s.stop()

	upid, err := upid.Parse(fmt.Sprintf("slave@%s", ts.Listener.Addr().String()))
	assert.NoError(t, err)

	checker := NewSlaveHealthChecker(upid, 10, time.Millisecond*10, time.Millisecond*10)
	ch := checker.Start()
	defer checker.Stop()

	select {
	case <-time.After(time.Second):
		t.Error("timeout")
	case <-ch:
		assert.True(t, atomic.LoadInt32(&s.th.cnt) > 10)
	}

	// TODO(jdef) hack: this sucks, but there's a data race in httptest's handler when Close()
	// and ServeHTTP() are invoked (WaitGroup DATA RACE). Sleeping here to attempt to avoid that.
	// I think this is supposed to be fixed in go1.6
	time.Sleep(5 * time.Second)
}
func TestSchedCacheContainsOffer(t *testing.T) {
	cache := newSchedCache()
	offer01 := createTestOffer("01")
	pid01, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)
	offer02 := createTestOffer("02")
	pid02, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)

	cache.putOffer(offer01, pid01)
	cache.putOffer(offer02, pid02)

	assert.True(t, cache.containsOffer(util.NewOfferID("test-offer-01")))
	assert.True(t, cache.containsOffer(util.NewOfferID("test-offer-02")))
	assert.False(t, cache.containsOffer(util.NewOfferID("test-offer-05")))
}
Beispiel #13
0
func (driver *MesosSchedulerDriver) resourcesOffered(from *upid.UPID, pbMsg proto.Message) {
	log.V(2).Infoln("Handling resource offers.")

	msg := pbMsg.(*mesos.ResourceOffersMessage)
	if driver.status == mesos.Status_DRIVER_ABORTED {
		log.Infoln("Ignoring ResourceOffersMessage, the driver is aborted!")
		return
	}

	if !driver.connected {
		log.Infoln("Ignoring ResourceOffersMessage, the driver is not connected!")
		return
	}

	pidStrings := msg.GetPids()
	if len(pidStrings) != len(msg.Offers) {
		log.Errorln("Ignoring offers, Offer count does not match Slave PID count.")
		return
	}

	for i, offer := range msg.Offers {
		if pid, err := upid.Parse(pidStrings[i]); err == nil {
			driver.cache.putOffer(offer, pid)
			log.V(2).Infof("Cached offer %s from SlavePID %s", offer.Id.GetValue(), pid)
		} else {
			log.Warningf("Failed to parse offer PID '%v': %v", pid, err)
		}
	}

	driver.withScheduler(func(s Scheduler) { s.ResourceOffers(driver, msg.Offers) })
}
func TestSlaveHealthCheckerPartitonedSlave(t *testing.T) {
	t.Skip("skipping known flaky test (fails on busy CI servers, should use a fake clock)")

	s := newPartitionedServer(5, 9)
	ts := httptest.NewUnstartedServer(s)
	ts.Start()
	defer ts.Close()

	t.Log("test server listening on", ts.Listener.Addr())
	upid, err := upid.Parse(fmt.Sprintf("slave@%s", ts.Listener.Addr().String()))
	assert.NoError(t, err)

	checker := NewSlaveHealthChecker(upid, 10, time.Millisecond*10, time.Millisecond*10)
	ch := checker.Start()
	defer func() {
		checker.Stop()
		<-checker.stop
	}()

	select {
	case <-time.After(2 * time.Second):
		actual := atomic.LoadInt32(&checker.continuousUnhealthyCount)
		assert.EqualValues(t, 0, actual, "expected 0 unhealthy counts instead of %d", actual)
	case <-ch:
		t.Fatal("Shouldn't get unhealthy notification")
	}
}
func TestMutatedHostUPid(t *testing.T) {
	serverId := "testserver"
	serverPort := getNewPort()
	serverHost := "127.0.0.1"
	serverAddr := serverHost + ":" + strconv.Itoa(serverPort)

	// override the upid.Host with this listener IP
	addr := net.ParseIP("127.0.0.2")

	// setup receiver (server) process
	uPid, err := upid.Parse(fmt.Sprintf("%s@%s", serverId, serverAddr))
	assert.NoError(t, err)
	receiver := NewHTTPTransporter(uPid, addr)

	err = receiver.listen()
	assert.NoError(t, err)

	if receiver.upid.Host != "127.0.0.1" {
		t.Fatalf("reciever.upid.Host was expected to return %s, got %s\n", serverHost, receiver.upid.Host)
	}

	if receiver.upid.Port != strconv.Itoa(serverPort) {
		t.Fatalf("receiver.upid.Port was expected to return %d, got %s\n", serverPort, receiver.upid.Port)
	}
}
func getLibprocessFrom(r *http.Request) (*upid.UPID, error) {
	if r.Method != "POST" {
		return nil, fmt.Errorf("Not a POST request")
	}
	ua, ok := r.Header["User-Agent"]
	if ok && strings.HasPrefix(ua[0], "libprocess/") {
		// TODO(yifan): Just take the first field for now.
		return upid.Parse(ua[0][len("libprocess/"):])
	}
	lf, ok := r.Header["Libprocess-From"]
	if ok {
		// TODO(yifan): Just take the first field for now.
		return upid.Parse(lf[0])
	}
	return nil, fmt.Errorf("Cannot find 'User-Agent' or 'Libprocess-From'")
}
func TestTransporterStartAndStop(t *testing.T) {
	serverId := "testserver"
	serverPort := getNewPort()
	serverAddr := "127.0.0.1:" + strconv.Itoa(serverPort)

	// setup receiver (server) process
	rcvPid, err := upid.Parse(fmt.Sprintf("%s@%s", serverId, serverAddr))
	assert.NoError(t, err)
	receiver := NewHTTPTransporter(rcvPid, nil)

	errch := receiver.Start()
	assert.NotNil(t, errch)

	time.Sleep(1 * time.Second)
	receiver.Stop(false)

	select {
	case <-time.After(2 * time.Second):
		t.Fatalf("timed out waiting for transport to stop")
	case err := <-errch:
		if err != nil {
			t.Fatalf(err.Error())
		}
	}
}
func TestTransporterSend(t *testing.T) {
	idreg := regexp.MustCompile(`[A-Za-z0-9_\-]+@[A-Za-z0-9_\-\.]+:[0-9]+`)
	serverId := "testserver"

	// setup mesos client-side
	fromUpid, err := upid.Parse(fmt.Sprintf("mesos1@localhost:%d", getNewPort()))
	assert.NoError(t, err)

	protoMsg := testmessage.GenerateSmallMessage()
	msgName := getMessageName(protoMsg)
	msg := &Message{
		Name:         msgName,
		ProtoMessage: protoMsg,
	}
	requestURI := fmt.Sprintf("/%s/%s", serverId, msgName)

	// setup server-side
	msgReceived := make(chan struct{})
	srv := makeMockServer(requestURI, func(rsp http.ResponseWriter, req *http.Request) {
		defer close(msgReceived)
		from := req.Header.Get("Libprocess-From")
		assert.NotEmpty(t, from)
		assert.True(t, idreg.MatchString(from), fmt.Sprintf("regexp failed for '%v'", from))
	})
	defer srv.Close()
	toUpid, err := upid.Parse(fmt.Sprintf("%s@%s", serverId, srv.Listener.Addr().String()))
	assert.NoError(t, err)

	// make transport call.
	transport := NewHTTPTransporter(fromUpid, nil)
	errch := transport.Start()
	defer transport.Stop(false)

	msg.UPID = toUpid
	err = transport.Send(context.TODO(), msg)
	assert.NoError(t, err)

	select {
	case <-time.After(2 * time.Second):
		t.Fatalf("timed out waiting for message receipt")
	case <-msgReceived:
	case err := <-errch:
		if err != nil {
			t.Fatalf(err.Error())
		}
	}
}
func TestTransporter_DiscardedSend(t *testing.T) {
	serverId := "testserver"

	// setup mesos client-side
	protoMsg := testmessage.GenerateSmallMessage()
	msgName := getMessageName(protoMsg)
	msg := &Message{
		Name:         msgName,
		ProtoMessage: protoMsg,
	}
	requestURI := fmt.Sprintf("/%s/%s", serverId, msgName)

	// setup server-side
	msgReceived := make(chan struct{})
	srv := makeMockServer(requestURI, func(rsp http.ResponseWriter, req *http.Request) {
		close(msgReceived)
		time.Sleep(2 * time.Second) // long enough that we should be able to stop it
	})
	defer srv.Close()
	toUpid, err := upid.Parse(fmt.Sprintf("%s@%s", serverId, srv.Listener.Addr().String()))
	assert.NoError(t, err)

	// make transport call.
	transport := NewHTTPTransporter(upid.UPID{ID: "mesos1", Host: "localhost"}, nil)
	_, errch := transport.Start()
	defer transport.Stop(false)

	msg.UPID = toUpid
	senderr := make(chan struct{})
	go func() {
		defer close(senderr)
		err = transport.Send(context.TODO(), msg)
		assert.NotNil(t, err)
		assert.Equal(t, discardOnStopError, err)
	}()

	// wait for message to be received
	select {
	case <-time.After(2 * time.Second):
		t.Fatalf("timed out waiting for message receipt")
		return
	case <-msgReceived:
		transport.Stop(false)
	case err := <-errch:
		if err != nil {
			t.Fatalf(err.Error())
			return
		}
	}

	// wait for send() to process discarded-error
	select {
	case <-time.After(5 * time.Second):
		t.Fatalf("timed out waiting for aborted send")
		return
	case <-senderr: // continue
	}
}
func TestTransporterNew(t *testing.T) {
	id, err := upid.Parse(fmt.Sprintf("mesos1@localhost:%d", getNewPort()))
	assert.NoError(t, err)
	trans := NewHTTPTransporter(id, nil)
	assert.NotNil(t, trans)
	assert.NotNil(t, trans.upid)
	assert.NotNil(t, trans.messageQueue)
	assert.NotNil(t, trans.client)
}
func TestSchedulerDriverNew_WithPid(t *testing.T) {
	masterAddr := "[email protected]:5050"
	mUpid, err := upid.Parse(masterAddr)
	assert.NoError(t, err)
	driver := newTestSchedulerDriver(t, NewMockScheduler(), &mesos.FrameworkInfo{}, masterAddr, nil)
	driver.handleMasterChanged(driver.self, &mesos.InternalMasterChangeDetected{Master: &mesos.MasterInfo{Pid: proto.String(mUpid.String())}})
	assert.True(t, driver.MasterPid.Equal(mUpid), fmt.Sprintf("expected upid %+v instead of %+v", mUpid, driver.MasterPid))
	assert.NoError(t, err)
}
func TestSchedCacheGetOffer(t *testing.T) {
	cache := newSchedCache()
	offer01 := createTestOffer("01")
	pid01, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)
	offer02 := createTestOffer("02")
	pid02, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)

	cache.putOffer(offer01, pid01)
	cache.putOffer(offer02, pid02)

	cachedOffer01 := cache.getOffer(util.NewOfferID("test-offer-01")).offer
	cachedOffer02 := cache.getOffer(util.NewOfferID("test-offer-02")).offer
	assert.NotEqual(t, offer01, cachedOffer02)
	assert.Equal(t, offer01, cachedOffer01)
	assert.Equal(t, offer02, cachedOffer02)

}
func (m *MockDetector) Detect(listener detector.MasterChanged) error {
	if listener != nil {
		if pid, err := upid.Parse("master(2)@" + m.address); err != nil {
			return err
		} else {
			go listener.OnMasterChanged(detector.CreateMasterInfo(pid))
		}
	}
	return nil
}
func TestSchedCacheGetSlavePid(t *testing.T) {
	cache := newSchedCache()

	pid01, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)
	pid02, err := upid.Parse("[email protected]:5050")
	assert.NoError(t, err)

	cache.putSlavePid(util.NewSlaveID("slave01"), pid01)
	cache.putSlavePid(util.NewSlaveID("slave02"), pid02)

	cachedSlavePid1 := cache.getSlavePid(util.NewSlaveID("slave01"))
	cachedSlavePid2 := cache.getSlavePid(util.NewSlaveID("slave02"))

	assert.NotNil(t, cachedSlavePid1)
	assert.NotNil(t, cachedSlavePid2)
	assert.True(t, pid01.Equal(cachedSlavePid1))
	assert.True(t, pid02.Equal(cachedSlavePid2))
	assert.False(t, pid01.Equal(cachedSlavePid2))
}
Beispiel #25
0
func NewMockSlaveHttpServer(t *testing.T, handler func(rsp http.ResponseWriter, req *http.Request)) *MockMesosHttpServer {
	server := httptest.NewServer(http.HandlerFunc(handler))
	assert.NotNil(t, server)
	addr := server.Listener.Addr().String()
	pid, err := upid.Parse("slave(1)@" + addr)
	assert.NoError(t, err)
	assert.NotNil(t, pid)
	assert.NoError(t, os.Setenv("MESOS_SLAVE_PID", pid.String()))
	assert.NoError(t, os.Setenv("MESOS_SLAVE_ID", "test-slave-001"))
	log.Infoln("Created test Slave http server with PID", pid.String())
	return &MockMesosHttpServer{PID: pid, Addr: addr, server: server, t: t}
}
func BenchmarkMessengerSendMixedMessage(b *testing.B) {
	messages := generateMixedMessages(1000)

	wg := new(sync.WaitGroup)
	wg.Add(b.N)
	srv := runTestServer(b, wg)
	defer srv.Close()

	upid1, err := upid.Parse(fmt.Sprintf("mesos1@localhost:%d", getNewPort()))
	assert.NoError(b, err)
	upid2, err := upid.Parse(fmt.Sprintf("testserver@%s", srv.Listener.Addr().String()))
	assert.NoError(b, err)

	m1 := NewHttp(upid1)
	assert.NoError(b, m1.Start())

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		m1.Send(context.TODO(), upid2, messages[i%1000])
	}
	wg.Wait()
}
func (suite *SchedulerTestSuite) TestSchdulerDriverAcceptOffersWithError() {
	sched := mock_scheduler.New()
	sched.On("StatusUpdate").Return(nil)
	sched.On("Error").Return()

	msgr := mockedMessenger()
	driver := newTestDriver(suite.T(), driverConfigMessenger(sched, suite.framework, suite.master, nil, msgr))
	driver.OnDispatch(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.CacheOffer(offer, pid)

	// launch task
	task := util.NewTaskInfo(
		"simple-task",
		util.NewTaskID("simpe-task-1"),
		util.NewSlaveID("test-slave-001"),
		[]*mesos.Resource{util.NewScalarResourceWithReservation("mem", 400, "principal", "role")},
	)
	task.Command = util.NewCommandInfo("pwd")
	task.Executor = util.NewExecutorInfo(util.NewExecutorID("test-exec"), task.Command)
	tasks := []*mesos.TaskInfo{task}

	operations := []*mesos.Offer_Operation{util.NewLaunchOperation(tasks)}

	stat, err := driver.AcceptOffers(
		[]*mesos.OfferID{offer.Id},
		operations,
		&mesos.Filters{},
	)
	suite.Equal(mesos.Status_DRIVER_RUNNING, stat)
	suite.Error(err)
}
func TestMessenger(t *testing.T) {
	messages := generateMixedMessages(1000)

	upid1, err := upid.Parse(fmt.Sprintf("mesos1@localhost:%d", getNewPort()))
	assert.NoError(t, err)
	upid2, err := upid.Parse(fmt.Sprintf("mesos2@localhost:%d", getNewPort()))
	assert.NoError(t, err)

	m1 := NewHttp(upid1)
	m2 := NewHttp(upid2)

	done := make(chan struct{})
	counts := make([]int, 4)
	msgQueue := make([]proto.Message, 0, len(messages))
	installMessages(t, m2, &msgQueue, &counts, done)

	assert.NoError(t, m1.Start())
	assert.NoError(t, m2.Start())

	go func() {
		for _, msg := range messages {
			assert.NoError(t, m1.Send(context.TODO(), upid2, msg))
		}
	}()

	select {
	case <-time.After(time.Second * 10):
		t.Fatalf("Timeout")
	case <-done:
	}

	for i := range counts {
		assert.Equal(t, 1000, counts[i])
	}
	assert.Equal(t, messages, msgQueue)
}
func TestSlaveHealthCheckerPartitonedSlave(t *testing.T) {
	s := newPartitionedServer(5, 9)
	ts := httptest.NewUnstartedServer(s)
	ts.Start()
	defer ts.Close()

	upid, err := upid.Parse(fmt.Sprintf("slave@%s", ts.Listener.Addr().String()))
	assert.NoError(t, err)

	checker := NewSlaveHealthChecker(upid, 10, time.Millisecond*10, time.Millisecond*10)
	ch := checker.Start()
	defer checker.Stop()

	select {
	case <-time.After(time.Second):
		assert.Equal(t, 0, checker.continuousUnhealthyCount)
	case <-ch:
		t.Fatal("Shouldn't get unhealthy notification")
	}
}
func TestSlaveHealthCheckerFailedOnErrorStatusSlave(t *testing.T) {
	s := newErrorStatusServer(5)
	ts := httptest.NewUnstartedServer(s)
	ts.Start()
	defer ts.Close()

	upid, err := upid.Parse(fmt.Sprintf("slave@%s", ts.Listener.Addr().String()))
	assert.NoError(t, err)

	checker := NewSlaveHealthChecker(upid, 10, time.Millisecond*10, time.Millisecond*10)
	ch := checker.Start()
	defer checker.Stop()

	select {
	case <-time.After(time.Second):
		t.Fatal("timeout")
	case <-ch:
		assert.True(t, atomic.LoadInt32(&s.th.cnt) > 10)
	}
}