| name | vibe-concurrent-test-safety |
| description | Audits tests for concurrency safety — race conditions, shared mock state, cleanup ordering. Use when writing tests that involve goroutines, async operations, or shared mutable state. |
| user-invocable | true |
vibe-concurrent-test-safety
Flaky tests are almost always concurrency bugs in the test, not the code.
When to Use This Skill
- Writing tests that launch goroutines or async operations
- Tests use shared mock objects accessed by multiple goroutines
- Tests that fail intermittently ("flaky")
- After adding
-race flag and getting failures
- Tests that involve daemon/server startup and shutdown
When NOT to Use This Skill
- Purely synchronous tests with no concurrency
- Tests that are already race-free (verified with
-race flag)
- Simple mock-based tests with single-threaded access
Common Concurrency Bugs in Tests
1. Direct Mock State Access
go daemon.Run(ctx)
time.Sleep(100 * time.Millisecond)
assert.Equal(t, 3, len(mock.Requests))
go daemon.Run(ctx)
time.Sleep(100 * time.Millisecond)
assert.Equal(t, 3, mock.RequestCount())
2. Missing Context Cancellation Before Cleanup
go daemon.Run(ctx)
defer bus.Close()
go daemon.Run(ctx)
defer func() {
cancel()
<-daemon.Done()
bus.Close()
}()
3. Assertions on Timing
go startServer()
time.Sleep(50 * time.Millisecond)
resp := callServer()
go startServer()
waitForReady(server)
resp := callServer()
Audit Checklist
Output Format
Concurrent Test Safety Audit: [Test File]
Issues Found: X
| # | Issue | Line | Fix |
|---|
| 1 | Direct mock access | :42 | Use mock.RequestCount() |
| 2 | Missing cancel before Close | :15 | Add cancel() before defer |
Suggested Fixes
[Code snippets for each fix]