diff --git a/remoting/etcdv3/client_test.go b/remoting/etcdv3/client_test.go index e37b6383df..9a5ef60993 100644 --- a/remoting/etcdv3/client_test.go +++ b/remoting/etcdv3/client_test.go @@ -154,7 +154,7 @@ func (suite *ClientTestSuite) TestClientValid() { c := suite.client t := suite.T() - if c.Valid() != true { + if !c.Valid() { t.Fatal("client is not valid") } c.Close() @@ -174,7 +174,7 @@ func (suite *ClientTestSuite) TestClientDone() { c.Wait.Wait() - if c.Valid() == true { + if c.Valid() { suite.T().Fatal("client should be invalid then") } } diff --git a/remoting/etcdv3/facade.go b/remoting/etcdv3/facade.go index 3f5999fdf3..2edbb66508 100644 --- a/remoting/etcdv3/facade.go +++ b/remoting/etcdv3/facade.go @@ -85,10 +85,8 @@ LOOP: ) logger.Infof("ETCDV3ProviderRegistry.validateETCDV3Client(etcd Addr{%s}) = error{%#v}", endpoint, perrors.WithStack(err)) - if err == nil { - if r.RestartCallBack() { - break - } + if err == nil && r.RestartCallBack() { + break } failTimes++ if MaxFailTimes <= failTimes { diff --git a/remoting/kubernetes/client_test.go b/remoting/kubernetes/client_test.go index e116c48b1a..d6c5a2e880 100644 --- a/remoting/kubernetes/client_test.go +++ b/remoting/kubernetes/client_test.go @@ -59,6 +59,9 @@ var tests = []struct { // test dataset prefix const prefix = "name" +var ( + watcherStopLog = "the watcherSet watcher was stopped" +) var clientPodListJsonData = `{ "apiVersion": "v1", "items": [ @@ -258,12 +261,12 @@ func TestClientValid(t *testing.T) { client := getTestClient(t) defer client.Close() - if client.Valid() != true { + if !client.Valid() { t.Fatal("client is not valid") } client.Close() - if client.Valid() != false { + if client.Valid() { t.Fatal("client is valid") } } @@ -278,7 +281,7 @@ func TestClientDone(t *testing.T) { <-client.Done() - if client.Valid() == true { + if client.Valid() { t.Fatal("client should be invalid") } } @@ -331,7 +334,7 @@ func TestClientGetChildrenKVList(t *testing.T) { return } case <-done: - t.Log("the watcherSet watcher was stopped") + t.Log(watcherStopLog) return } } @@ -399,7 +402,7 @@ func TestClientWatchPrefix(t *testing.T) { case e := <-wc: t.Logf("got event %v k %s v %s", e.EventType, e.Key, e.Value) case <-done: - t.Log("the watcherSet watcher was stopped") + t.Log(watcherStopLog) return } } @@ -441,7 +444,7 @@ func TestClientWatch(t *testing.T) { case e := <-wc: t.Logf("got event %v k %s v %s", e.EventType, e.Key, e.Value) case <-done: - t.Log("the watcherSet watcher was stopped") + t.Log(watcherStopLog) return } } diff --git a/remoting/kubernetes/facade_test.go b/remoting/kubernetes/facade_test.go index 4323c0ec56..65c5d715a3 100644 --- a/remoting/kubernetes/facade_test.go +++ b/remoting/kubernetes/facade_test.go @@ -48,6 +48,7 @@ func (r *mockFacade) GetUrl() common.URL { } func (r *mockFacade) Destroy() { + // TODO implementation me } func (r *mockFacade) RestartCallBack() bool { diff --git a/remoting/zookeeper/facade.go b/remoting/zookeeper/facade.go index 10de42523e..f9b9332504 100644 --- a/remoting/zookeeper/facade.go +++ b/remoting/zookeeper/facade.go @@ -78,10 +78,8 @@ LOOP: err = ValidateZookeeperClient(r, WithZkName(zkName)) logger.Infof("ZkProviderRegistry.validateZookeeperClient(zkAddr{%s}) = error{%#v}", zkAddress, perrors.WithStack(err)) - if err == nil { - if r.RestartCallBack() { - break - } + if err == nil && r.RestartCallBack() { + break } failTimes++ if MaxFailTimes <= failTimes { diff --git a/remoting/zookeeper/listener_test.go b/remoting/zookeeper/listener_test.go index ba7d6ba81b..37ef1b4b96 100644 --- a/remoting/zookeeper/listener_test.go +++ b/remoting/zookeeper/listener_test.go @@ -32,6 +32,10 @@ import ( "github.com/apache/dubbo-go/remoting" ) +var ( + dubboPropertiesPath = "/dubbo/dubbo.properties" +) + func initZkData(t *testing.T) (*zk.TestCluster, *ZookeeperClient, <-chan zk.Event) { ts, client, event, err := NewMockZookeeperClient("test", 15*time.Second) assert.NoError(t, err) @@ -58,10 +62,10 @@ func initZkData(t *testing.T) (*zk.TestCluster, *ZookeeperClient, <-chan zk.Even dubbo.service.com.ikurento.user.UserProvider.cluster=failover ` - err = client.Create("/dubbo/dubbo.properties") + err = client.Create(dubboPropertiesPath) assert.NoError(t, err) - _, err = client.Conn.Set("/dubbo/dubbo.properties", []byte(data), 0) + _, err = client.Conn.Set(dubboPropertiesPath, []byte(data), 0) assert.NoError(t, err) return ts, client, event @@ -99,7 +103,7 @@ func TestListener(t *testing.T) { dataListener := &mockDataListener{client: client, changedData: changedData, wait: &wait} listener.ListenServiceEvent(nil, "/dubbo", dataListener) time.Sleep(1 * time.Second) - _, err := client.Conn.Set("/dubbo/dubbo.properties", []byte(changedData), 1) + _, err := client.Conn.Set(dubboPropertiesPath, []byte(changedData), 1) assert.NoError(t, err) wait.Wait() assert.Equal(t, changedData, dataListener.eventList[1].Content)