From 2b3b74f24ae93ae9cfca5cb9a890dd966dc3b615 Mon Sep 17 00:00:00 2001
From: fangyincheng <fangyincheng@sina.com>
Date: Thu, 27 Jun 2019 20:07:03 +0800
Subject: [PATCH] Fix:fix test & some spelling problems

---
 cluster/loadbalance/least_active.go   | 2 +-
 config/service_config_test.go         | 3 ++-
 protocol/dubbo/client_test.go         | 6 +++---
 protocol/dubbo/codec.go               | 6 +++---
 protocol/dubbo/dubbo_invoker_test.go  | 2 +-
 protocol/dubbo/dubbo_protocol_test.go | 2 +-
 protocol/dubbo/listener.go            | 2 +-
 protocol/jsonrpc/server.go            | 4 +++-
 8 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/cluster/loadbalance/least_active.go b/cluster/loadbalance/least_active.go
index d7d305681..695ca21b0 100644
--- a/cluster/loadbalance/least_active.go
+++ b/cluster/loadbalance/least_active.go
@@ -50,7 +50,7 @@ func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation
 	var (
 		leastActive  int32 = -1                 // The least active value of all invokers
 		totalWeight  int64 = 0                  // The number of invokers having the same least active value (LEAST_ACTIVE)
-		firstWeight  int64 = 0                  // Initial value, used for comparision
+		firstWeight  int64 = 0                  // Initial value, used for comparison
 		leastIndexes       = make([]int, count) // The index of invokers having the same least active value (LEAST_ACTIVE)
 		leastCount         = 0                  // The number of invokers having the same least active value (LEAST_ACTIVE)
 		sameWeight         = true               // Every invoker has the same weight value?
diff --git a/config/service_config_test.go b/config/service_config_test.go
index 77cbbff38..99835f630 100644
--- a/config/service_config_test.go
+++ b/config/service_config_test.go
@@ -122,7 +122,8 @@ func Test_Export(t *testing.T) {
 	doinit()
 	extension.SetProtocol("registry", GetProtocol)
 
-	for _, service := range providerConfig.Services {
+	for i := 0; i < len(providerConfig.Services); i++ {
+		service := providerConfig.Services[i]
 		service.Implement(&MockService{})
 		service.Export()
 		assert.Condition(t, func() bool {
diff --git a/protocol/dubbo/client_test.go b/protocol/dubbo/client_test.go
index 1ea9e4fb0..f4a5f4a84 100644
--- a/protocol/dubbo/client_test.go
+++ b/protocol/dubbo/client_test.go
@@ -40,7 +40,7 @@ func TestClient_CallOneway(t *testing.T) {
 	proto, url := InitTest(t)
 
 	c := &Client{
-		pendingResponses: make(map[SequenceType]*PendingResponse),
+		pendingResponses: new(sync.Map),
 		conf:             *clientConf,
 	}
 	c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL))
@@ -57,7 +57,7 @@ func TestClient_Call(t *testing.T) {
 	proto, url := InitTest(t)
 
 	c := &Client{
-		pendingResponses: make(map[SequenceType]*PendingResponse),
+		pendingResponses: new(sync.Map),
 		conf:             *clientConf,
 	}
 	c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL))
@@ -118,7 +118,7 @@ func TestClient_AsyncCall(t *testing.T) {
 	proto, url := InitTest(t)
 
 	c := &Client{
-		pendingResponses: make(map[SequenceType]*PendingResponse),
+		pendingResponses: new(sync.Map),
 		conf:             *clientConf,
 	}
 	c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL))
diff --git a/protocol/dubbo/codec.go b/protocol/dubbo/codec.go
index e9ced8449..cb57fc896 100644
--- a/protocol/dubbo/codec.go
+++ b/protocol/dubbo/codec.go
@@ -40,9 +40,9 @@ const (
 type CallType int32
 
 const (
-	CT_UNKOWN CallType = 0
-	CT_OneWay CallType = 1
-	CT_TwoWay CallType = 2
+	CT_UNKNOWN CallType = 0
+	CT_OneWay  CallType = 1
+	CT_TwoWay  CallType = 2
 )
 
 ////////////////////////////////////////////
diff --git a/protocol/dubbo/dubbo_invoker_test.go b/protocol/dubbo/dubbo_invoker_test.go
index 4368bb463..182d6d8e0 100644
--- a/protocol/dubbo/dubbo_invoker_test.go
+++ b/protocol/dubbo/dubbo_invoker_test.go
@@ -36,7 +36,7 @@ func TestDubboInvoker_Invoke(t *testing.T) {
 	proto, url := InitTest(t)
 
 	c := &Client{
-		pendingResponses: make(map[SequenceType]*PendingResponse),
+		pendingResponses: new(sync.Map),
 		conf:             *clientConf,
 	}
 	c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL))
diff --git a/protocol/dubbo/dubbo_protocol_test.go b/protocol/dubbo/dubbo_protocol_test.go
index 3543d8da8..26ce4a190 100644
--- a/protocol/dubbo/dubbo_protocol_test.go
+++ b/protocol/dubbo/dubbo_protocol_test.go
@@ -48,7 +48,7 @@ func TestDubboProtocol_Export(t *testing.T) {
 	eq := exporter.GetInvoker().GetUrl().URLEqual(url)
 	assert.True(t, eq)
 
-	// second service: the same path and the diferent version
+	// second service: the same path and the different version
 	url2, err := common.NewURL(context.Background(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&"+
 		"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+
 		"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&"+
diff --git a/protocol/dubbo/listener.go b/protocol/dubbo/listener.go
index 15e222676..55ee92930 100644
--- a/protocol/dubbo/listener.go
+++ b/protocol/dubbo/listener.go
@@ -190,7 +190,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
 
 	p, ok := pkg.(*DubboPackage)
 	if !ok {
-		logger.Errorf("illegal packge{%#v}", pkg)
+		logger.Errorf("illegal package{%#v}", pkg)
 		return
 	}
 	p.Header.ResponseStatus = hessian.Response_OK
diff --git a/protocol/jsonrpc/server.go b/protocol/jsonrpc/server.go
index 5b5548067..22dc7cfc4 100644
--- a/protocol/jsonrpc/server.go
+++ b/protocol/jsonrpc/server.go
@@ -152,7 +152,9 @@ func (s *Server) handlePkg(conn net.Conn) {
 			timeout, err := time.ParseDuration(reqHeader["Timeout"])
 			if err == nil {
 				httpTimeout = timeout
-				ctx, _ = context.WithTimeout(ctx, httpTimeout)
+				var cancel context.CancelFunc
+				ctx, cancel = context.WithTimeout(ctx, httpTimeout)
+				defer cancel()
 			}
 			delete(reqHeader, "Timeout")
 		}
-- 
GitLab