Files
gitea/models/audit/audit_event_benchmark_test.go
T
bircni da37b7916b feat: Add audit logging (#38189)
Co-authored-by: bircni <bircni@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-09-12 08:15:23 +00:00

42 lines
989 B
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package audit
import (
"context"
"testing"
"gitea.dev/models/unittest"
"gitea.dev/modules/timeutil"
)
// BenchmarkInsertEvent measures the synchronous database cost added when audit
// recording is enabled. Keep it separate from router benchmarks so it remains
// comparable across changes to request handling.
func BenchmarkInsertEvent(b *testing.B) {
if err := unittest.PrepareTestDatabase(); err != nil {
b.Fatal(err)
}
ctx := context.Background()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
event := &Event{
Action: UserPassword,
ActorID: 1,
ActorName: "actor",
ScopeType: ScopeUser,
ScopeID: 2,
ScopeName: "scope",
Origin: OriginUI,
Metadata: `{"source":"benchmark"}`,
TimestampUnix: timeutil.TimeStamp(i + 1),
}
if err := InsertEvent(ctx, event); err != nil {
b.Fatal(err)
}
}
}