# panic: 执行测试期间检测到竞争

- **ID:** `go/race-detector-in-test`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 -race 下运行的测试启动了共享状态且无同步的 goroutine，竞争检测器中止了测试二进制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.1+ | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   var wg sync.WaitGroup
wg.Add(1)
go func() { defer wg.Done(); mutateShared() }()
wg.Wait()
   ```
2. **** (90% 成功率)
   ```
   go test -race -run TestFoo ./...
// read the two conflicting stacks and add a mutex around both
   ```

## 无效尝试

- **** — Shuffling changes timing but the unsynchronized access remains and the race recurs. (80% 失败率)
- **** — The race is inside the test's own goroutines, not between tests, so serializing tests does not help. (75% 失败率)
