|
|
|
@ -38,8 +38,44 @@ func mockServerManager() (logger *log.Logger, shutdownCh chan struct{}) {
|
|
|
|
|
// func (sm *ServerManager) AddServer(server *server_details.ServerDetails) {
|
|
|
|
|
|
|
|
|
|
// func (sm *ServerManager) CycleFailedServers() {
|
|
|
|
|
// func (sm *ServerManager) FindServer() (server *server_details.ServerDetails) {
|
|
|
|
|
func TestServerManager_FindServer(t *testing.T) {
|
|
|
|
|
sm := testServerManager()
|
|
|
|
|
|
|
|
|
|
// func (sm *ServerManager) FindHealthyServer() (server *server_details.ServerDetails) {
|
|
|
|
|
s1 := sm.FindServer()
|
|
|
|
|
if s1 == nil {
|
|
|
|
|
t.Fatalf("Expected non-nil server")
|
|
|
|
|
}
|
|
|
|
|
if s1.Name != "s1" {
|
|
|
|
|
t.Fatalf("Expected s1 server")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s1 = sm.FindServer()
|
|
|
|
|
if s1 == nil || s1.Name != "s1" {
|
|
|
|
|
t.Fatalf("Expected s1 server (still)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sm.AddServer(&server_details.ServerDetails{Name: "s2"})
|
|
|
|
|
if sm.NumServers() != 2 {
|
|
|
|
|
t.Fatalf("Expected two servers")
|
|
|
|
|
}
|
|
|
|
|
s1 = sm.FindServer()
|
|
|
|
|
if s1 == nil || s1.Name != "s1" {
|
|
|
|
|
t.Fatalf("Expected s1 server (still)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sm.NotifyFailedServer(s1)
|
|
|
|
|
s2 := sm.FindServer()
|
|
|
|
|
if s2 == nil || s2.Name != "s2" {
|
|
|
|
|
t.Fatalf("Expected s2 server")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sm.NotifyFailedServer(s2)
|
|
|
|
|
s1 = sm.FindServer()
|
|
|
|
|
if s1 == nil || s1.Name != "s1" {
|
|
|
|
|
t.Fatalf("Expected s1 server")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// func (sm *ServerManager) GetNumServers() (numServers int) {
|
|
|
|
|
func TestServerManager_GetNumServers(t *testing.T) {
|
|
|
|
|