fix(server): 修复 TestSubscribeTask_ConcurrentSafety 数据竞争问题

- 修复多个 goroutine 并发 append 同一 slice 导致的 DATA RACE
- 使用预分配 slice + 索引赋值替代并发 append
- 通过 go test -race 验证
This commit is contained in:
2026-07-29 14:47:31 +08:00
parent 11a92c429f
commit 0027704169
@@ -354,14 +354,14 @@ func TestSubscribeTask_ConcurrentSafety(t *testing.T) {
const goroutines = 50
// 并发订阅
cancels := make([]func(), 0, goroutines)
cancels := make([]func(), goroutines)
for i := 0; i < goroutines; i++ {
wg.Add(1)
go func() {
go func(idx int) {
defer wg.Done()
_, cancel := svc.SubscribeTask(taskID)
cancels = append(cancels, cancel)
}()
cancels[idx] = cancel
}(i)
}
wg.Wait()