forked from baron/baron-sso
kratos SSOT 재설계
This commit is contained in:
46
backend/internal/handler/user_handler_live_test.go
Normal file
46
backend/internal/handler/user_handler_live_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"baron-sso-backend/internal/service"
|
||||
"context"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestUserHandler_LiveWarmIdentityMirrorLatency(t *testing.T) {
|
||||
if os.Getenv("BARON_LIVE_IDENTITY_MIRROR_TEST") != "1" {
|
||||
t.Skip("set BARON_LIVE_IDENTITY_MIRROR_TEST=1 to run against local Kratos and Redis")
|
||||
}
|
||||
|
||||
redisService, err := service.NewRedisService()
|
||||
if err != nil {
|
||||
t.Fatalf("connect redis: %v", err)
|
||||
}
|
||||
kratosAdmin := service.NewKratosAdminService()
|
||||
handler := &UserHandler{
|
||||
KratosAdmin: kratosAdmin,
|
||||
IdentityCache: redisService,
|
||||
}
|
||||
|
||||
startedAt := time.Now()
|
||||
count, err := handler.WarmIdentityMirror(context.Background())
|
||||
elapsed := time.Since(startedAt)
|
||||
if err != nil {
|
||||
t.Fatalf("warm identity mirror: %v", err)
|
||||
}
|
||||
|
||||
maxMillis := int64(2000)
|
||||
if raw := os.Getenv("BARON_LIVE_IDENTITY_MIRROR_MAX_MS"); raw != "" {
|
||||
parsed, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || parsed <= 0 {
|
||||
t.Fatalf("invalid BARON_LIVE_IDENTITY_MIRROR_MAX_MS=%q", raw)
|
||||
}
|
||||
maxMillis = parsed
|
||||
}
|
||||
t.Logf("identity mirror warmup identities=%d elapsed=%s max=%dms", count, elapsed, maxMillis)
|
||||
if elapsed > time.Duration(maxMillis)*time.Millisecond {
|
||||
t.Fatalf("identity mirror warmup took %s, over %dms", elapsed, maxMillis)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user