(t *testing.T)
| 294 | } |
| 295 | |
| 296 | func TestInMemoryAuditLog_ConcurrentWrites(t *testing.T) { |
| 297 | auditLog := NewInMemoryAuditLog(nil) |
| 298 | defer func() { _ = auditLog.Close() }() |
| 299 | |
| 300 | // 并发写入事件 |
| 301 | done := make(chan bool) |
| 302 | for i := range 10 { |
| 303 | go func(id int) { |
| 304 | event := AuditEvent{ |
| 305 | Type: AuditTypeUserLogin, |
| 306 | UserID: "user" + string(rune('0'+id)), |
| 307 | Message: "Concurrent login", |
| 308 | } |
| 309 | _ = auditLog.LogEvent(event) |
| 310 | done <- true |
| 311 | }(i) |
| 312 | } |
| 313 | |
| 314 | // 等待所有操作完成 |
| 315 | for range 10 { |
| 316 | <-done |
| 317 | } |
| 318 | |
| 319 | // 使用GetStatus而不是直接访问events字段 |
| 320 | status := auditLog.GetStatus() |
| 321 | if status.TotalEvents != 10 { |
| 322 | t.Errorf("expected 10 events, got %d", status.TotalEvents) |
| 323 | } |
| 324 | } |
nothing calls this directly
no test coverage detected