fix/status-review-sync-20260409 #1

Merged
long merged 65 commits from fix/status-review-sync-20260409 into main 2026-04-18 15:05:51 +00:00
3 changed files with 9 additions and 9 deletions
Showing only changes of commit a754545072 - Show all commits

View File

@@ -103,7 +103,7 @@ func runTokenValidationConcurrencyTest(t *testing.T, testName string, config Con
jwtManager := auth.NewJWT("concurrent-test-secret", 2*time.Hour, 7*24*time.Hour)
tokens := make([]string, 100)
for i := 0; i < 100; i++ {
accessToken, _, err := jwtManager.GenerateTokenPair(int64(i+1), fmt.Sprintf("user%d", i))
accessToken, _, err := jwtManager.GenerateTokenPair(int64(i+1), fmt.Sprintf("user%d", i), 0)
if err != nil {
t.Fatalf("生成Token失败: %v", err)
}
@@ -192,7 +192,7 @@ func runConcurrencyTest(t *testing.T, testName string, config ConcurrencyTestCon
}
reqStart := time.Now()
// 模拟 Token 生成操作(代替真实登录)
_, _, err := jwtManager.GenerateTokenPair(int64(id+1), fmt.Sprintf("user%d", id))
_, _, err := jwtManager.GenerateTokenPair(int64(id+1), fmt.Sprintf("user%d", id), 0)
latency := time.Since(reqStart)
mu.Lock()
latencies = append(latencies, latency)

View File

@@ -68,13 +68,13 @@ func BenchmarkJWTGenerateToken(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, _ = jwtManager.GenerateTokenPair(int64(i), "testuser")
_, _, _ = jwtManager.GenerateTokenPair(int64(i), "testuser", 0)
}
}
func BenchmarkJWTValidateToken(b *testing.B) {
jwtManager := auth.NewJWT("benchmark-secret-key-32bytes!", 2*time.Hour, 7*24*time.Hour)
token, _, _ := jwtManager.GenerateTokenPair(1, "testuser")
token, _, _ := jwtManager.GenerateTokenPair(1, "testuser", 0)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -87,7 +87,7 @@ func BenchmarkJWTGenerateAndValidate(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
token, _, _ := jwtManager.GenerateTokenPair(int64(i), "testuser")
token, _, _ := jwtManager.GenerateTokenPair(int64(i), "testuser", 0)
jwtManager.ValidateAccessToken(token)
}
}

View File

@@ -148,7 +148,7 @@ func BenchmarkTokenGeneration(b *testing.B) {
for i := 0; i < b.N; i++ {
start := time.Now()
_, _, err := jwtManager.GenerateTokenPair(1, "benchuser")
_, _, err := jwtManager.GenerateTokenPair(1, "benchuser", 0)
latency := time.Since(start).Nanoseconds()
metrics.RecordLatency(latency)
if err == nil {
@@ -165,7 +165,7 @@ func BenchmarkTokenGeneration(b *testing.B) {
// BenchmarkTokenValidation JWT验证性能测试
func BenchmarkTokenValidation(b *testing.B) {
jwtManager := auth.NewJWT("benchmark-secret", 2*time.Hour, 7*24*time.Hour)
accessToken, _, err := jwtManager.GenerateTokenPair(1, "benchuser")
accessToken, _, err := jwtManager.GenerateTokenPair(1, "benchuser", 0)
if err != nil {
b.Fatalf("生成Token失败: %v", err)
}
@@ -201,7 +201,7 @@ func TestP99LatencyThreshold(t *testing.T) {
operation: func() time.Duration {
jwtManager := auth.NewJWT("test-secret", 2*time.Hour, 7*24*time.Hour)
start := time.Now()
jwtManager.GenerateTokenPair(1, "testuser")
jwtManager.GenerateTokenPair(1, "testuser", 0)
return time.Since(start)
},
thresholdMs: 100,
@@ -322,7 +322,7 @@ func TestMemoryUsage(t *testing.T) {
jwtManager := auth.NewJWT("test-secret", 2*time.Hour, 7*24*time.Hour)
for i := 0; i < 10000; i++ {
accessToken, _, _ := jwtManager.GenerateTokenPair(int64(i%100), "testuser")
accessToken, _, _ := jwtManager.GenerateTokenPair(int64(i%100), "testuser", 0)
jwtManager.ValidateAccessToken(accessToken)
}