1kasa commented on code in PR #2879:
URL: https://github.com/apache/dubbo-go/pull/2879#discussion_r2097255477
##########
registry/nacos/registry_test.go:
##########
@@ -374,3 +376,104 @@ func Test_nacosRegistry_Subscribe(t *testing.T) {
})
}
}
+
+func TestNacosRegistryDestroy(t *testing.T) {
+ ctrl := gomock.NewController(t)
+ defer ctrl.Finish()
+
+ mockNamingClient := NewMockINamingClient(ctrl)
+ nc := &nacosClient.NacosNamingClient{}
+ nc.SetClient(mockNamingClient)
+
+ regURL, _ := common.NewURL("registry://127.0.0.1:8848")
+ nr := &nacosRegistry{
+ URL: regURL,
+ namingClient: nc,
+ done: make(chan struct{}),
+ registryUrls: []*common.URL{},
+ }
+
+ serviceURL1, _ :=
common.NewURL("dubbo://127.0.0.1:20001/com.example.Service1?interface=com.example.Service1&group=test&version=1.0.0")
+ serviceURL2, _ :=
common.NewURL("dubbo://127.0.0.1:20002/com.example.Service2?interface=com.example.Service2&group=test&version=1.0.0")
+
+ nr.registryUrls = append(nr.registryUrls, serviceURL1)
+ nr.registryUrls = append(nr.registryUrls, serviceURL2)
+
+
mockNamingClient.EXPECT().DeregisterInstance(gomock.Any()).Times(len(nr.registryUrls)).Return(true,
nil)
+
+ var wg sync.WaitGroup
+ wg.Add(1)
+
+ go func() {
+ defer wg.Done()
+ <-nr.done
+ t.Log("nr.done channel closed")
+ }()
+
+ nr.Destroy()
+
+ wg.Wait()
+}
+
+func TestNacosListenerClose(t *testing.T) {
+ ctrl := gomock.NewController(t)
+ defer ctrl.Finish()
+
+ mockNamingClient := NewMockINamingClient(ctrl)
+ nc := &nacosClient.NacosNamingClient{}
+ nc.SetClient(mockNamingClient)
+
+ regURL, _ :=
common.NewURL("registry://127.0.0.1:8848?registry.group=testgroup")
+ serviceName := "com.example.TestService"
+
+ nl := NewNacosListenerWithServiceName(serviceName, regURL, nc)
+
+ subscribeParam := &vo.SubscribeParam{
+ ServiceName: serviceName,
+ GroupName: "testgroup",
+ SubscribeCallback: nl.Callback,
+ }
+ nl.subscribeParam = subscribeParam
+
+
mockNamingClient.EXPECT().Unsubscribe(subscribeParam).Times(1).Return(nil)
+
+ nl.Close()
+
+ select {
+ case <-nl.done:
+ default:
+ t.Errorf("nl.done channel was not closed after Close()")
+ }
+}
+
+func TestNacosListenerNextAfterClose(t *testing.T) {
Review Comment:
done
--
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]