Copilot commented on code in PR #1075:
URL: 
https://github.com/apache/incubator-seata-go/pull/1075#discussion_r2986547554


##########
pkg/remoting/loadbalance/loadbalance_test.go:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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 loadbalance
+
+import (
+       "sync"
+       "testing"
+
+       "github.com/golang/mock/gomock"
+       "github.com/stretchr/testify/assert"
+
+       "seata.apache.org/seata-go/v2/pkg/remoting/mock"
+       "seata.apache.org/seata-go/v2/pkg/remoting/rpc"
+)
+
+func TestSelect_ConsistentHashLoadBalance(t *testing.T) {
+       resetConsistentHashState()
+       t.Cleanup(resetConsistentHashState)
+
+       ctrl := gomock.NewController(t)
+       sessions := &sync.Map{}
+
+       session := mock.NewMockTestSession(ctrl)
+       session.EXPECT().IsClosed().Return(false).AnyTimes()
+       session.EXPECT().RemoteAddr().Return("127.0.0.1:8000").MinTimes(1)
+       sessions.Store(session, "session-1")
+
+       result := Select(consistentHashLoadBalance, sessions, "test_xid")
+       assert.NotNil(t, result)

Review Comment:
   `TestSelect_ConsistentHashLoadBalance` will pass even if `Select` falls back 
to `RandomLoadBalance` (because only one session is present, both strategies 
return non-nil). To make this a real regression test for selector dispatch, 
assert an observable side effect of the consistent-hash path (e.g., 
`consistentInstance` becomes non-nil after the call) or otherwise validate 
deterministic consistent-hash behavior with multiple sessions.
   ```suggestion
        assert.NotNil(t, result)
        assert.NotNil(t, consistentInstance)
   ```



##########
pkg/remoting/loadbalance/loadbalance_test.go:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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 loadbalance
+
+import (
+       "sync"
+       "testing"
+
+       "github.com/golang/mock/gomock"
+       "github.com/stretchr/testify/assert"
+
+       "seata.apache.org/seata-go/v2/pkg/remoting/mock"
+       "seata.apache.org/seata-go/v2/pkg/remoting/rpc"
+)
+
+func TestSelect_ConsistentHashLoadBalance(t *testing.T) {
+       resetConsistentHashState()
+       t.Cleanup(resetConsistentHashState)
+
+       ctrl := gomock.NewController(t)
+       sessions := &sync.Map{}
+
+       session := mock.NewMockTestSession(ctrl)
+       session.EXPECT().IsClosed().Return(false).AnyTimes()
+       session.EXPECT().RemoteAddr().Return("127.0.0.1:8000").MinTimes(1)
+       sessions.Store(session, "session-1")
+
+       result := Select(consistentHashLoadBalance, sessions, "test_xid")
+       assert.NotNil(t, result)
+}
+
+func TestSelect_LeastActiveLoadBalance(t *testing.T) {
+       ctrl := gomock.NewController(t)
+       sessions := &sync.Map{}
+
+       busyAddr := "127.0.0.1:8000"
+       idleAddr := "127.0.0.2:8000"
+
+       busySession := mock.NewMockTestSession(ctrl)
+       busySession.EXPECT().IsClosed().Return(false).AnyTimes()
+       busySession.EXPECT().RemoteAddr().Return(busyAddr).MinTimes(1)
+
+       idleSession := mock.NewMockTestSession(ctrl)
+       idleSession.EXPECT().IsClosed().Return(false).AnyTimes()
+       idleSession.EXPECT().RemoteAddr().Return(idleAddr).MinTimes(1)
+
+       sessions.Store(busySession, "busy")
+       sessions.Store(idleSession, "idle")
+
+       rpc.BeginCount(busyAddr)
+       t.Cleanup(func() {
+               rpc.RemoveStatus(busyAddr)
+               rpc.RemoveStatus(idleAddr)
+       })

Review Comment:
   This test depends on global RPC status state (`rpc.serviceStatusMap`). Other 
tests in this package call `rpc.BeginCount` for the same addresses (e.g. 
`127.0.0.2:8000`) without cleanup, so `idleAddr` may already have a non-zero 
Active count and cause order-dependent failures. Consider calling 
`rpc.RemoveStatus(busyAddr)`/`rpc.RemoveStatus(idleAddr)` (or otherwise 
resetting status) before `rpc.BeginCount(...)` to make the test deterministic.



-- 
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]

Reply via email to