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


##########
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:
   [P2] 上一轮建议不完整,实测修正:移出 RACE_SKIP_TESTS 后,不带覆盖率插桩的 `-race` 会稳定命中 agollo 内部竞态
   
   上一轮我只看到"修复没进整仓门禁",没有验证移出后的实际结果。补齐实测后结论相反:本行(`Makefile` 删除 `TestListener` 
的改动)应当保留在 skip 名单里,但理由不是本仓库代码。
   
   实测(head `299d3a2b`,darwin/amd64,go1.25.0,GOCACHE 定向到 review 缓存目录):
   
   - `go test -race -count=1 ./config_center/apollo/` → **7/7 FAIL**,报 
`WARNING: DATA 
RACE`:`github.com/apolloconfig/agollo/[email protected]/component/remote/async.go:72` 读 
`c.appConfig`,与 `client.go:188` `SyncAndUpdate` 写 `c.appConfig.NamespaceName` 
冲突;`--- FAIL: TestListener`
   - 同命令加 `-skip '^TestListener$'` → PASS(1.1s)
   - 加上 CI 的 `-covermode=atomic -coverprofile=...` → 3/3 PASS(`make test-race` 
走的就是这条,所以当前 CI 是绿的)
   - base `cca439ea` 对照:包含 `TestListener` 时同样 DATA RACE,`-skip 
'^TestListener$'` 时 PASS
   
   即:该竞态是 agollo v4.4.0 的既有问题,与本 PR 对 `apolloDataListener` / `mockConfigRes` 
的加锁无关;但只要 `TestListener` 参与执行就会被触发。移出 skip 后的后果:
   
   1. `make test-race` 的绿灯依赖 `-coverprofile` 插桩带来的时序变化(去掉插桩 7/7 红),属于时序巧合,Go 
版本、runner 核数或插桩实现变化都可能翻红;
   2. 任何不走覆盖率的 race 验证(`go test -race ./config_center/apollo/`、IDE 的 race 
运行)在该包上 100% 失败,且失败记在 `TestListener` 名下,会持续误导后续维护者。
   
   另外正文已与当前 Diff 不一致:Verification 段仍写着 "`TestListener` remains in 
`RACE_SKIP_TESTS` because ... a separate race inside Agollo",需要同步修改。
   
   建议二选一:
   
   - 恢复 `TestListener` 到 `RACE_SKIP_TESTS`,并在该行注释里写明根因是 agollo v4.4.0 
`async.go:72` 读 / `client.go:188` 写,避免下一轮又被当成"修复没进门禁";
   - 或让 `TestListener` 不与遗留的 agollo 刷新 goroutine 共存(独立包或独立测试二进制),再移出 skip。
   
   本 PR 自身的锁改造与新增并发用例是有效的:把 `OnNewestChange` 
的快照与锁去掉做变异后,`TestApolloListenerConcurrentAccess` 立即报 `runtime.mapassign` DATA 
RACE(实测),说明该用例能检出原缺陷。
   



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