MCPcopy Create free account
hub / github.com/astercloud/aster / TestInMemoryAuditLog_ConcurrentWrites

Function TestInMemoryAuditLog_ConcurrentWrites

pkg/security/audit_test.go:296–324  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

294}
295
296func 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}

Callers

nothing calls this directly

Calls 4

CloseMethod · 0.95
LogEventMethod · 0.95
GetStatusMethod · 0.95
NewInMemoryAuditLogFunction · 0.85

Tested by

no test coverage detected