Gitesg commented on code in PR #3830:
URL: https://github.com/apache/dubbo-go/pull/3830#discussion_r4586813916


##########
config_center/apollo/impl_test.go:
##########
@@ -304,48 +319,65 @@ func TestListener(t *testing.T) {
        listener := &apolloDataListener{}
        listener.wg.Add(2)
        apollo := initMockApollo(t)
-       mockConfigRes = `{
+       setMockConfigRes(`{
        "appId": "testApplication_yang",
        "cluster": "default",
        "namespaceName": "mockDubbogo.yaml",
        "configurations": {
                "registries.hangzhouzk.username": "11111"
        },
        "releaseKey": "20191104105242-0f13805d89f834a4"
-}`
+}`)
        // test add
        apollo.AddListener(mockNamespace, listener)
        listener.wg.Wait()
-       assert.Equal(t, "mockDubbogo.yaml", listener.event)
-       assert.Positive(t, listener.count)
+       count, event := listener.snapshot()
+       assert.Equal(t, "mockDubbogo.yaml", event)
+       assert.Positive(t, count)
 
        // test remove
        apollo.RemoveListener(mockNamespace, listener)
        listenerCount := 0
        apollo.listeners.Range(func(_, value any) bool {
-               apolloListener := value.(*apolloListener)
-               for e := range apolloListener.listeners {
-                       t.Logf("listener:%v", e)
+               al := value.(*apolloListener)
+
+               if !al.IsEmpty() {
                        listenerCount++
                }
+
                return true
        })
        assert.Equal(t, 0, listenerCount)
 }
 
 type apolloDataListener struct {
        wg    sync.WaitGroup
+       mu    sync.Mutex
        count int
        event string
 }
 
 func (l *apolloDataListener) Process(configType 
*config_center.ConfigChangeEvent) {
+
        if configType.ConfigType != remoting.EventTypeUpdate {
                return
        }
-       l.wg.Done()
+
+       l.mu.Lock()
        l.count++
        l.event = configType.Key
+       done := l.count <= 2

Review Comment:
   Thanks for the review. I've removed TestListener from RACE_SKIP_TESTS in the 
Makefile. The test passes independently under -race, including the new 
concurrent-access test. The CI race-test workflow has also passed with this 
change.



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