Some checks failed
CI / Build & Test (push) Failing after 1m31s
- Add user management endpoints (list/create/get/update/delete) with pagination and search - Add dashboard stats endpoint with tenant/user/online counts and growth metrics - Add tenant resolver middleware for multi-tenant request scoping - Add i18n kernel with zh/en message files and AcceptLanguage middleware - Add WebSocket hub/handler for real-time communication - Add job scheduler kernel with cron support - Add plugin sandbox for isolated execution - Add storage kernel (local filesystem) - Add event bus kernel for pub/sub - Add cache kernel abstraction - Add database migration runner and version upgrade checker - Add rate limiting middleware with Redis backend - Add SQL migrations for rbac, audit_logs, settings, notifications, examples - Extend user repository with list/delete/count operations - Register all module routes with tenant resolver
107 lines
2.4 KiB
Go
107 lines
2.4 KiB
Go
package benchmarks
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"mengstack/internal/modules/auth/application"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func BenchmarkJWT_GenerateToken(b *testing.B) {
|
|
secret := "benchmark-secret-key-for-testing-only"
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := application.GenerateToken(1, "tenant-1", "access", 15*time.Minute, secret, "mengstack")
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkJWT_ParseToken(b *testing.B) {
|
|
secret := "benchmark-secret-key-for-testing-only"
|
|
token, err := application.GenerateToken(1, "tenant-1", "access", 15*time.Minute, secret, "mengstack")
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := application.ParseToken(token, secret)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkBcrypt_Hash(b *testing.B) {
|
|
password := "benchmark-password-12345"
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := bcrypt.GenerateFromPassword([]byte(password), 12)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkBcrypt_Compare(b *testing.B) {
|
|
password := "benchmark-password-12345"
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), 12)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = bcrypt.CompareHashAndPassword(hash, []byte(password))
|
|
}
|
|
}
|
|
|
|
func BenchmarkBcrypt_Compare_Wrong(b *testing.B) {
|
|
password := "benchmark-password-12345"
|
|
wrong := "wrong-password-67890"
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), 12)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = bcrypt.CompareHashAndPassword(hash, []byte(wrong))
|
|
}
|
|
}
|
|
|
|
func BenchmarkJWT_Throughput(b *testing.B) {
|
|
secret := "benchmark-secret-key-for-testing-only"
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
i := uint(0)
|
|
for pb.Next() {
|
|
token, err := application.GenerateToken(i, "tenant-1", "access", 15*time.Minute, secret, "mengstack")
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
_, err = application.ParseToken(token, secret)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
i++
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkBcrypt_CostComparison(b *testing.B) {
|
|
password := "benchmark-password-12345"
|
|
for _, cost := range []int{10, 12, 14} {
|
|
b.Run(fmt.Sprintf("cost_%d", cost), func(b *testing.B) {
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := bcrypt.GenerateFromPassword([]byte(password), cost)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|