Skip to content

Commit

Permalink
update case
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx authored and mergify-bot committed Dec 9, 2020
1 parent df3d07e commit 68a4c3a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cluster/roundrobin/round_robin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func TestSelectHost(t *testing.T) {

//check servers
server.SetNextTryConnTime(appConfig.GetHost(), 5)
firstHost := balanace.Load(server.GetServers(appConfig.GetHost()))
Assert(t, host, NotEqual(firstHost.HomepageURL))
server.SetDownNode(appConfig.GetHost(), firstHost.HomepageURL)
firstHost := balanace.Load(server.GetServers(appConfig.GetHost())).HomepageURL
Assert(t, host, NotEqual(firstHost))
server.SetDownNode(appConfig.GetHost(), firstHost)

secondHost := balanace.Load(server.GetServers(appConfig.GetHost())).HomepageURL
Assert(t, host, NotEqual(secondHost))
Expand Down
5 changes: 3 additions & 2 deletions component/serverlist/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ func getTestAppConfig() *config.AppConfig {

func TestSyncServerIpListSuccessCallBack(t *testing.T) {
appConfig := getTestAppConfig()
SyncServerIPListSuccessCallBack([]byte(servicesConfigResponseStr), http.CallBack{AppConfigFunc: func() config.AppConfig {
serverMap, _ := SyncServerIPListSuccessCallBack([]byte(servicesConfigResponseStr), http.CallBack{AppConfigFunc: func() config.AppConfig {
return *appConfig
}})
Assert(t, server.GetServersLen(appConfig.GetHost()), Equal(10))
m := serverMap.(map[string]*config.ServerInfo)
Assert(t, len(m), Equal(10))
}

func TestSetDownNode(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions env/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ func SetServers(configIp string, serverMap map[string]*config.ServerInfo) {
}

//SetDownNode 设置失效节点
func SetDownNode(host string, configIp string) {
func SetDownNode(configIp string, host string) {
serverLock.Lock()
defer serverLock.Unlock()
s := ipMap[configIp]
if host == "" || s == nil {
if host == "" || s == nil || len(s.serverMap) == 0 {
return
}

Expand All @@ -93,14 +93,14 @@ func SetDownNode(host string, configIp string) {
}

//IsConnectDirectly is connect by ip directly
//false : no
//true : yes
//false : yes
//true : no
func IsConnectDirectly(configIp string) bool {
serverLock.Lock()
defer serverLock.Unlock()
s := ipMap[configIp]
if s == nil {
return true
if s == nil || len(s.serverMap) == 0 {
return false
}
if s.nextTryConnTime >= 0 && s.nextTryConnTime > time.Now().Unix() {
return true
Expand Down
2 changes: 1 addition & 1 deletion env/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ func TestAppConfig_IsConnectDirectly(t *testing.T) {

SetNextTryConnTime(name, 10)
isConnectDirectly = IsConnectDirectly(name)
Assert(t, isConnectDirectly, Equal(true))
Assert(t, isConnectDirectly, Equal(false))
}
4 changes: 4 additions & 0 deletions protocol/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ func RequestRecovery(appConfig config.AppConfig,
requestURL := fmt.Sprintf(format, host, connectConfig.URI)
response, err = Request(requestURL, connectConfig, callBack)
if err == nil {
return response, nil
}

if host == appConfig.GetHost() {
return response, err
}

Expand Down

0 comments on commit 68a4c3a

Please sign in to comment.