You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2019/08/20 08:30:33 UTC

[rocketmq-client-go] branch native updated: add GetNamesrv round-robin strategy testing (#159)

This is an automated email from the ASF dual-hosted git repository.

dinglei pushed a commit to branch native
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-go.git


The following commit(s) were added to refs/heads/native by this push:
     new ac41607  add GetNamesrv round-robin strategy testing (#159)
ac41607 is described below

commit ac4160710a86470f15514b2fbb945c60c81003ad
Author: cloes <wa...@163.com>
AuthorDate: Tue Aug 20 16:30:28 2019 +0800

    add GetNamesrv round-robin strategy testing (#159)
    
    * update mockgen command line,in order to fix generate file "import cycle not allowed" problem
    
    * update defaultConsumer.client init AND add push_consumer testing
    
    * fix bug:UpdateTopicRouteInfo() now can be called anytime
    
    * add GetNamesrv round-robin strategy testing
---
 internal/namesrv_test.go | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/internal/namesrv_test.go b/internal/namesrv_test.go
index 2994877..145acff 100644
--- a/internal/namesrv_test.go
+++ b/internal/namesrv_test.go
@@ -18,8 +18,10 @@ limitations under the License.
 package internal
 
 import (
+	"sync"
 	"testing"
 
+	. "github.com/smartystreets/goconvey/convey"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -61,3 +63,27 @@ func TestSelector(t *testing.T) {
 	assert.Equal(t, srvs[3], namesrv.GetNamesrv())
 	assert.Equal(t, srvs[0], namesrv.GetNamesrv())
 }
+
+func TestGetNamesrv(t *testing.T) {
+	Convey("Test GetNamesrv round-robin strategy", t, func() {
+		ns := &Namesrvs{
+			srvs: []string{"192.168.100.1",
+				"192.168.100.2",
+				"192.168.100.3",
+				"192.168.100.4",
+				"192.168.100.5",
+			},
+			lock: new(sync.Mutex),
+		}
+
+		index1 := ns.index
+		IP1 := ns.GetNamesrv()
+
+		index2 := ns.index
+		IP2 := ns.GetNamesrv()
+
+		So(index1+1, ShouldEqual, index2)
+		So(IP1, ShouldEqual, ns.srvs[index1])
+		So(IP2, ShouldEqual, ns.srvs[index2])
+	})
+}