From a7545450724d656daeed9a69c100507ae8c5ec14 Mon Sep 17 00:00:00 2001 From: long-agent Date: Sat, 18 Apr 2026 20:16:45 +0800 Subject: [PATCH] fix: add missing PCE parameter to GenerateTokenPair calls in test files The JWT GenerateTokenPair functions were updated to require a PCE (Password Changed Epoch) parameter for token invalidation. This commit updates test files in concurrent and performance packages to include this parameter. - internal/concurrent/concurrent_test.go: 2 call sites fixed - internal/performance/benchmark_test.go: 3 call sites fixed - internal/performance/performance_test.go: 4 call sites fixed --- internal/concurrent/concurrent_test.go | 4 ++-- internal/performance/benchmark_test.go | 6 +++--- internal/performance/performance_test.go | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/concurrent/concurrent_test.go b/internal/concurrent/concurrent_test.go index 6e2957e..84e1a7f 100644 --- a/internal/concurrent/concurrent_test.go +++ b/internal/concurrent/concurrent_test.go @@ -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) diff --git a/internal/performance/benchmark_test.go b/internal/performance/benchmark_test.go index a2719ca..497bda8 100644 --- a/internal/performance/benchmark_test.go +++ b/internal/performance/benchmark_test.go @@ -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) } } diff --git a/internal/performance/performance_test.go b/internal/performance/performance_test.go index b332bbf..34a2a05 100644 --- a/internal/performance/performance_test.go +++ b/internal/performance/performance_test.go @@ -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) }