yumosx commented on code in PR #3046:
URL: https://github.com/apache/dubbo-go/pull/3046#discussion_r2508740692
##########
cluster/loadbalance/p2c/loadbalance_test.go:
##########
@@ -101,28 +91,23 @@ func TestLoadBalance(t *testing.T) {
url1, _ :=
common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
url2, _ :=
common.NewURL("dubbo://192.168.1.2:20000/com.ikurento.user.UserProvider")
+ // P2C algorithm randomly selects 2 invokers, so we need to
mock all possible combinations
m.EXPECT().
- GetMethodMetrics(gomock.Eq(url0),
gomock.Eq(invocation.MethodName()), gomock.Eq(metrics.HillClimbing)).
- Times(1).
+ GetMethodMetrics(gomock.Any(),
gomock.Eq(invocation.MethodName()), gomock.Eq(metrics.HillClimbing)).
+ Times(2).
Return(uint64(10), nil)
- m.EXPECT().
- GetMethodMetrics(gomock.Eq(url1),
gomock.Eq(invocation.MethodName()), gomock.Eq(metrics.HillClimbing)).
- Times(1).
- Return(uint64(5), nil)
ivkArr := []base.Invoker{
base.NewBaseInvoker(url0),
base.NewBaseInvoker(url1),
base.NewBaseInvoker(url2),
}
- ivk := lb.Select(ivkArr, invocation)
-
- assert.Equal(t, ivkArr[0].GetURL().String(),
ivk.GetURL().String())
+ got := lb.Select(ivkArr, invocation)
+ assert.NotNil(t, got)
Review Comment:
@Alanxtl 这是因为算法选择的是随机数,没有办法去预测, 之前使用那个算法已经在 go1.24 给 drop 了
##########
cluster/loadbalance/p2c/loadbalance_test.go:
##########
@@ -101,28 +91,23 @@ func TestLoadBalance(t *testing.T) {
url1, _ :=
common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
url2, _ :=
common.NewURL("dubbo://192.168.1.2:20000/com.ikurento.user.UserProvider")
+ // P2C algorithm randomly selects 2 invokers, so we need to
mock all possible combinations
m.EXPECT().
- GetMethodMetrics(gomock.Eq(url0),
gomock.Eq(invocation.MethodName()), gomock.Eq(metrics.HillClimbing)).
- Times(1).
+ GetMethodMetrics(gomock.Any(),
gomock.Eq(invocation.MethodName()), gomock.Eq(metrics.HillClimbing)).
+ Times(2).
Return(uint64(10), nil)
- m.EXPECT().
- GetMethodMetrics(gomock.Eq(url1),
gomock.Eq(invocation.MethodName()), gomock.Eq(metrics.HillClimbing)).
- Times(1).
- Return(uint64(5), nil)
ivkArr := []base.Invoker{
base.NewBaseInvoker(url0),
base.NewBaseInvoker(url1),
base.NewBaseInvoker(url2),
}
- ivk := lb.Select(ivkArr, invocation)
-
- assert.Equal(t, ivkArr[0].GetURL().String(),
ivk.GetURL().String())
+ got := lb.Select(ivkArr, invocation)
+ assert.NotNil(t, got)
Review Comment:
@Alanxtl 这是因为算法选择的是随机数,没有办法去预测, 之前使用那个 rand.seed 已经在 go1.24 给 drop 了
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]