AlexStocks commented on code in PR #3830:
URL: https://github.com/apache/dubbo-go/pull/3830#discussion_r4585768573
##########
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] TestListener 的并发问题已修,但它仍在 RACE_SKIP_TESTS 里,修复没进整仓门禁
触发条件:CI 的 Unit Test job 用 `make test-race` 跑整仓 race,Makefile 里是 `-skip
'^($(RACE_SKIP_TESTS))$'`;`TestListener` 仍在该名单中,所以本 PR 修掉的并发问题在整仓 race
跑里根本不会执行。真正需要改动的位置在 `Makefile` 的 `RACE_SKIP_TESTS`(head 第 46 行 `RACE_SKIP_TESTS
:= TestListener \`),不在本行。
证据(实测,head 712df70e,darwin/amd64,go1.25.0,GOCACHE 定向到 review 缓存目录):
- 本 PR 改造后:`go test -race -count=1 -run '^TestListener$'
./config_center/apollo/` → `ok`。
- 反向对照:把 `probes/base` 里的 `config_center/apollo/listener.go` 换成 base
cca439ea11 的版本、其余仍是 head,`go test -race -run TestApolloListenerConcurrentAccess
./config_center/apollo/` 报 `WARNING: DATA RACE`(`AddListener` 的
`mapaccess1`/`mapassign`,listener.go:67/68);head 同命令 `ok`。可见新用例确实能检出该缺陷。
实际影响:同批的同类修复都把用例移出了名单——#3826 移出 `TestTCPPackageHandle`、#3827 移出
`TestServiceDiscoveryRegistryUnRegister_Concurrent`、#3829 移出
`TestFailbackRetryFailed`/`TestFailbackOutOfLimit`(三者 head 的 `Race Test` 步骤均
completed/success)。这里不移除,`TestListener` 的并发回归只能靠单包手动 `-race`,整仓门禁再也拦不住同类回归。
修复方向:从 `RACE_SKIP_TESTS` 删除 `TestListener \`,并在 PR 描述里注明该列表项已通过 `make
test-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]