You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by jo...@apache.org on 2023/01/25 00:25:23 UTC
[incubator-eventmesh] branch master updated: [ISSUE #2899] refactor eventmesh-sdk-go http.selector module test code (#2900)
This is an automated email from the ASF dual-hosted git repository.
jonyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new f2f022e09 [ISSUE #2899] refactor eventmesh-sdk-go http.selector module test code (#2900)
f2f022e09 is described below
commit f2f022e09f50626a3b58c3d8d476bd7ff4f29bc8
Author: jonyangx <ya...@gmail.com>
AuthorDate: Wed Jan 25 08:25:16 2023 +0800
[ISSUE #2899] refactor eventmesh-sdk-go http.selector module test code (#2900)
* fix issue2899
* fix license check error
Co-authored-by: jonyangx <jo...@gmail.com>
---
eventmesh-dashboard/.env.development | 1 -
.../http/selector/random_selector_test.go | 61 +++++++++-------
.../http/selector/selector_suite_test.go | 30 ++++++++
.../http/selector/weight_random_selector_test.go | 82 ++++++++++++----------
.../selector/weight_round_robin_selector_test.go | 74 ++++++++++---------
5 files changed, 146 insertions(+), 102 deletions(-)
diff --git a/eventmesh-dashboard/.env.development b/eventmesh-dashboard/.env.development
index cb2fb63c3..7e0621fb8 100644
--- a/eventmesh-dashboard/.env.development
+++ b/eventmesh-dashboard/.env.development
@@ -17,6 +17,5 @@
* under the License.
*/
-
NEXT_PUBLIC_WORKFLOW_API_ROOT=http://175.27.131.65:11022
NEXT_PUBLIC_EVENTCATALOG_API_ROOT=http://175.27.131.65:12013
\ No newline at end of file
diff --git a/eventmesh-sdk-go/http/selector/random_selector_test.go b/eventmesh-sdk-go/http/selector/random_selector_test.go
index 7f43f8ed9..c6ad1f7f7 100644
--- a/eventmesh-sdk-go/http/selector/random_selector_test.go
+++ b/eventmesh-sdk-go/http/selector/random_selector_test.go
@@ -17,35 +17,42 @@ package selector
import (
"github.com/apache/incubator-eventmesh/eventmesh-sdk-go/http/conf"
- "github.com/stretchr/testify/assert"
- "testing"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
)
-func TestRandomLoadSelector_Select(t *testing.T) {
- testAddr := "192.168.0.1:10105;192.168.0.2:10105;192.168.0.3:10105;"
- eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
- eventMeshClientConfig.SetLoadBalanceType(RandomSelectorType)
- eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
+var _ = Describe("RandomLoadSelector test", func() {
- selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(), &eventMeshClientConfig)
- if err != nil {
- t.Fail()
- }
+ Context("Select test ", func() {
+ It("should success", func() {
+ testAddr := "192.168.0.1:10105;192.168.0.2:10105;192.168.0.3:10105;"
+ eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
+ eventMeshClientConfig.SetLoadBalanceType(RandomSelectorType)
+ eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
- for i := 0; i < 100; i++ {
- node := selector.Select()
- if node.Addr != "192.168.0.1:10105" && node.Addr != "192.168.0.2:10105" && node.Addr != "192.168.0.3:10105" {
- t.Fail()
- }
- }
-}
+ selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(),
+ &eventMeshClientConfig)
+ Ω(err).Should(BeNil())
-func TestRandomLoadSelector_GetType(t *testing.T) {
- eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
- eventMeshClientConfig.SetLoadBalanceType(RandomSelectorType)
- selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(), &eventMeshClientConfig)
- if err != nil {
- t.Fail()
- }
- assert.Equal(t, RandomSelectorType, selector.GetType())
-}
+ for i := 0; i < 100; i++ {
+ node := selector.Select()
+ Ω(node.Addr).Should(Or(
+ Equal("192.168.0.1:10105"),
+ Equal("192.168.0.2:10105"),
+ Equal("192.168.0.3:10105")),
+ )
+ }
+ })
+ })
+
+ Context("GetType test ", func() {
+ It("should success", func() {
+ eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
+ eventMeshClientConfig.SetLoadBalanceType(RandomSelectorType)
+ selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(),
+ &eventMeshClientConfig)
+ Ω(err).Should(BeNil())
+ Ω(selector.GetType()).Should(Equal(RandomSelectorType))
+ })
+ })
+})
diff --git a/eventmesh-sdk-go/http/selector/selector_suite_test.go b/eventmesh-sdk-go/http/selector/selector_suite_test.go
new file mode 100644
index 000000000..c9ad168a7
--- /dev/null
+++ b/eventmesh-sdk-go/http/selector/selector_suite_test.go
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package selector
+
+import (
+ "testing"
+
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+)
+
+func TestSelectorAPIs(t *testing.T) {
+ RegisterFailHandler(Fail)
+ RunSpecs(t, "selector module Tests")
+}
diff --git a/eventmesh-sdk-go/http/selector/weight_random_selector_test.go b/eventmesh-sdk-go/http/selector/weight_random_selector_test.go
index b65fed9f4..61000e445 100644
--- a/eventmesh-sdk-go/http/selector/weight_random_selector_test.go
+++ b/eventmesh-sdk-go/http/selector/weight_random_selector_test.go
@@ -17,45 +17,49 @@ package selector
import (
"github.com/apache/incubator-eventmesh/eventmesh-sdk-go/http/conf"
- "github.com/stretchr/testify/assert"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
"math"
- "testing"
)
-func TestWeightRandomLoadSelector_Select(t *testing.T) {
- testAddr := "192.168.0.1:10105:10;192.168.0.2:10105:20;192.168.0.3:10105:40;"
- eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
- eventMeshClientConfig.SetLoadBalanceType(WeightRandomSelectorType)
- eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
-
- selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(), &eventMeshClientConfig)
- if err != nil {
- t.Fail()
- }
-
- counter := make(map[string]int)
- testRange := 100_000
- for i := 0; i < testRange; i++ {
- node := selector.Select()
- counter[node.Addr]++
- }
-
- diff := float64(counter["192.168.0.3:10105"] - counter["192.168.0.2:10105"]*2)
- assert.True(t, math.Abs(diff) < float64(testRange/20))
-
- diff = float64(counter["192.168.0.3:10105"] - counter["192.168.0.1:10105"]*4)
- assert.True(t, math.Abs(diff) < float64(testRange/20))
-}
-
-func TestWeightRandomLoadSelector_GetType(t *testing.T) {
- testAddr := "192.168.0.1:10105:10;192.168.0.2:10105:20;192.168.0.3:10105:40;"
- eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
- eventMeshClientConfig.SetLoadBalanceType(WeightRandomSelectorType)
- eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
-
- selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(), &eventMeshClientConfig)
- if err != nil {
- t.Fail()
- }
- assert.Equal(t, WeightRandomSelectorType, selector.GetType())
-}
+var _ = Describe("WeightRandomLoadSelector test", func() {
+
+ Context("Select test ", func() {
+ It("should success", func() {
+ testAddr := "192.168.0.1:10105:10;192.168.0.2:10105:20;192.168.0.3:10105:40;"
+ eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
+ eventMeshClientConfig.SetLoadBalanceType(WeightRandomSelectorType)
+ eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
+
+ selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(),
+ &eventMeshClientConfig)
+ Ω(err).Should(BeNil())
+
+ counter := make(map[string]int)
+ testRange := 100_000
+ for i := 0; i < testRange; i++ {
+ node := selector.Select()
+ counter[node.Addr]++
+ }
+
+ diff := float64(counter["192.168.0.3:10105"] - counter["192.168.0.2:10105"]*2)
+ Ω(math.Abs(diff) < float64(testRange/20)).Should(BeTrue())
+
+ diff = float64(counter["192.168.0.3:10105"] - counter["192.168.0.1:10105"]*4)
+ Ω(math.Abs(diff) < float64(testRange/20)).Should(BeTrue())
+ })
+ })
+
+ Context("GetType test ", func() {
+ It("should success", func() {
+ testAddr := "192.168.0.1:10105:10;192.168.0.2:10105:20;192.168.0.3:10105:40;"
+ eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
+ eventMeshClientConfig.SetLoadBalanceType(WeightRandomSelectorType)
+ eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
+
+ selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(), &eventMeshClientConfig)
+ Ω(err).Should(BeNil())
+ Ω(selector.GetType()).To(Equal(WeightRandomSelectorType))
+ })
+ })
+})
diff --git a/eventmesh-sdk-go/http/selector/weight_round_robin_selector_test.go b/eventmesh-sdk-go/http/selector/weight_round_robin_selector_test.go
index d032532b1..f804ac641 100644
--- a/eventmesh-sdk-go/http/selector/weight_round_robin_selector_test.go
+++ b/eventmesh-sdk-go/http/selector/weight_round_robin_selector_test.go
@@ -17,40 +17,44 @@ package selector
import (
"github.com/apache/incubator-eventmesh/eventmesh-sdk-go/http/conf"
- "github.com/stretchr/testify/assert"
- "testing"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
)
-func TestWeightRoundRobinLoadSelector_Select(t *testing.T) {
- testAddr := "192.168.0.1:10105:10;192.168.0.2:10105:20;192.168.0.3:10105:30;"
- eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
- eventMeshClientConfig.SetLoadBalanceType(WeightRoundRobinSelectorType)
- eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
-
- selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(), &eventMeshClientConfig)
- if err != nil {
- t.Fail()
- }
-
- counter := make(map[string]int)
- testRange := 1000
- for i := 0; i < testRange; i++ {
- node := selector.Select()
- counter[node.Addr]++
- }
-
- assert.True(t, counter["192.168.0.2:10105"] > counter["192.168.0.1:10105"])
- assert.True(t, counter["192.168.0.3:10105"] > counter["192.168.0.2:10105"])
-}
-
-func TestWeightRoundRobinLoadSelector_GetType(t *testing.T) {
- testAddr := "192.168.0.1:10105:10;192.168.0.2:10105:20;192.168.0.3:10105:30;"
- eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
- eventMeshClientConfig.SetLoadBalanceType(WeightRoundRobinSelectorType)
- eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
- selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(), &eventMeshClientConfig)
- if err != nil {
- t.Fail()
- }
- assert.Equal(t, WeightRoundRobinSelectorType, selector.GetType())
-}
+var _ = Describe("WeightRoundRobinLoadSelector test", func() {
+
+ Context("Select test ", func() {
+ It("should success", func() {
+ testAddr := "192.168.0.1:10105:10;192.168.0.2:10105:20;192.168.0.3:10105:30;"
+ eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
+ eventMeshClientConfig.SetLoadBalanceType(WeightRoundRobinSelectorType)
+ eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
+
+ selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(), &eventMeshClientConfig)
+ Ω(err).Should(BeNil())
+
+ counter := make(map[string]int)
+ testRange := 1000
+ for i := 0; i < testRange; i++ {
+ node := selector.Select()
+ counter[node.Addr]++
+ }
+
+ Ω(counter["192.168.0.2:10105"] > counter["192.168.0.1:10105"]).Should(BeTrue())
+ Ω(counter["192.168.0.3:10105"] > counter["192.168.0.2:10105"]).Should(BeTrue())
+ })
+ })
+
+ Context("GetType test ", func() {
+ It("should success", func() {
+ testAddr := "192.168.0.1:10105:10;192.168.0.2:10105:20;192.168.0.3:10105:30;"
+ eventMeshClientConfig := conf.DefaultEventMeshHttpClientConfig
+ eventMeshClientConfig.SetLoadBalanceType(WeightRoundRobinSelectorType)
+ eventMeshClientConfig.SetLiteEventMeshAddr(testAddr)
+ selector, err := CreateNewSelector(eventMeshClientConfig.GetLoadBalanceType(),
+ &eventMeshClientConfig)
+ Ω(err).Should(BeNil())
+ Ω(selector.GetType()).To(Equal(WeightRoundRobinSelectorType))
+ })
+ })
+})
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org