Aias00 commented on code in PR #982:
URL: https://github.com/apache/dubbo-go-pixiu/pull/982#discussion_r3595633377


##########
pkg/adapter/llmregistry/registry/nacos/listener_test.go:
##########
@@ -77,6 +77,12 @@ func (m *mockNacosClient) Unsubscribe(param 
*vo.SubscribeParam) error {
        return nil
 }
 
+func (m *mockNacosClient) ServerHealthy() bool {
+       return true
+}
+
+func (m *mockNacosClient) CloseClient() {}

Review Comment:
   已处理(commit `0e94c1ee`)。在所有本次迁移的客户端创建点补齐了可达的关闭接口,取消订阅/停止后调用 
`CloseClient()`,并用 mock 断言关闭发生:
   
   - **llmregistry**:`NacosRegistry.DoUnsubscribe` 在停掉 listener 后调 
`client.CloseClient()`;抽出 `newNacosRegistryWithClient` 供测试注入 mock,新增 
`TestDoUnsubscribeClosesClient` 断言 `CloseClient` 被调用 1 次。
   - **springcloud**:`nacosServiceDiscovery.Unsubscribe` 末尾调 
`n.client.Close()`;client 字段抽象为 `nacosNamingClient` 接口(`*nacos.NacosClient` 
仍满足),mock 记录 `Close`,新增 `TestUnsubscribeClosesClient`。
   - **configcenter**:给 `ConfigClient`/`Load` 接口与 `ConfigManager` 加 
`Close()`,`NacosConfig.Close` 透传 SDK 
`CloseClient`,`TestDefaultConfigLoad_Close` 用 mock 断言转发。
   - **dubboregistry**:原 `DoUnsubscribe` 是 `panic("implement 
me")`,改为真实关闭(`Listener.Close` + `client.CloseClient`),与 `ZKRegistry` 对齐。
   - **pkg/remote/nacos**:`NacosClient.Close` 暴露 `namingClient.CloseClient()`。
   
   SDK 的 `CloseClient` 内部有 `isClosed` 守卫,幂等,重复 Stop 安全。



##########
pkg/adapter/springcloud/servicediscovery/nacos/nacos_test.go:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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 nacos
+
+import (
+       "testing"
+)
+
+import (
+       "github.com/nacos-group/nacos-sdk-go/v2/model"
+
+       "github.com/stretchr/testify/assert"
+)
+
+import (
+       
"github.com/apache/dubbo-go-pixiu/pkg/adapter/springcloud/servicediscovery"
+)
+
+func TestCallback_ServiceNameWithGroupPrefix(t *testing.T) {
+       // Test the @@ prefix stripping logic in Callback
+       // This tests the new code path where ServiceName contains 
"DEFAULT_GROUP@@service-name"
+
+       tests := []struct {
+               name        string
+               serviceName string
+               expected    string
+       }{
+               {
+                       name:        "with group prefix",
+                       serviceName: "DEFAULT_GROUP@@user-service",
+                       expected:    "user-service",
+               },
+               {
+                       name:        "without group prefix",
+                       serviceName: "user-service",
+                       expected:    "user-service",
+               },
+               {
+                       name:        "empty string",
+                       serviceName: "",
+                       expected:    "",
+               },
+               {
+                       name:        "multiple @@ separators",
+                       serviceName: "GROUP@@SUBGROUP@@service",
+                       expected:    "SUBGROUP@@service",
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       // Simulate the strings.Cut logic used in Callback
+                       serviceName := tt.serviceName
+                       if _, after, ok := cutServiceName(serviceName, "@@"); 
ok {
+                               serviceName = after
+                       }
+                       assert.Equal(t, tt.expected, serviceName)

Review Comment:
   已处理(commit `0e94c1ee`)。删除了复制的 `cutServiceName` 
实现。`TestCallback_ServiceNameWithGroupPrefix` 现在直接调用生产 
`nacosServiceDiscovery.Callback`:mock listener (`mockServiceEventListener`) 
记录收到的 `ServiceInstance`,断言 `ServiceName` 已剥离 `@@` 前缀。这样若生产代码删掉前缀处理、改错分隔符或没把结果传给 
listener,测试都会失败。



##########
pkg/adapter/springcloud/servicediscovery/nacos/nacos.go:
##########
@@ -118,7 +118,14 @@ func (n *nacosServiceDiscovery) Callback(services 
[]xdsmodel.SubscribeService, e
                        continue
                }
 
-               instance := fromSubscribeServiceToServiceInstance(service)
+               // v2 subscribe callback receives Instance directly (was 
SubscribeService in v1)
+               // ServiceName may contain group prefix like 
"DEFAULT_GROUP@@service-name", strip it
+               serviceName := service.ServiceName
+               if tmp := strings.Split(serviceName, "@@"); len(tmp) == 2 {
+                       serviceName = tmp[1]
+               }
+
+               instance := fromInstanceToServiceInstance(serviceName, service)

Review Comment:
   Already addressed in commit `233d147b` — the `@@` prefix strip now uses 
`strings.Cut(serviceName, "@@")` (split once, no extra allocation). See 
`nacos.go` `Callback`.



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