Skip to content

Commit c1b6e7f

Browse files
committed
fix(test): resolve benchmark failures in CI environment
- Add Docker availability checks to auth benchmarks to prevent NaN results - Implement silent loggers for cache and circuit breaker benchmarks - Update Makefile benchmark target to use -short flag for CI optimization - Eliminate excessive logging output that was overwhelming benchmark results Fixes: - BenchmarkCheckPasswordForSAMAccountName: Skip when Docker unavailable - BenchmarkCheckPasswordForDN: Skip when Docker unavailable - BenchmarkRegressionCircuitBreaker: Use discard logger to prevent log spam - Cache benchmarks: Use discard logger to eliminate noise All benchmarks now produce proper performance metrics instead of NaN results.
1 parent 740ef0a commit c1b6e7f

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ test-parallel: ## Run tests with maximum parallelization
5252

5353
test-benchmark: ## Run benchmark tests
5454
@echo "Running benchmark tests..."
55-
go test -bench=. -benchmem -timeout=$(TIMEOUT_ALL) $(BENCHMARK_PATTERN) ./...
55+
go test -bench=. -benchmem -short -timeout=$(TIMEOUT_ALL) $(BENCHMARK_PATTERN) ./...
5656

5757
test-coverage: ## Run tests with coverage report
5858
@echo "Running tests with coverage..."

auth_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package ldap
44

55
import (
66
"errors"
7+
"os/exec"
78
"strings"
89
"testing"
910

@@ -365,6 +366,12 @@ func BenchmarkCheckPasswordForSAMAccountName(b *testing.B) {
365366
if testing.Short() {
366367
b.Skip("Skipping integration benchmark in short mode")
367368
}
369+
370+
// Skip if Docker not available (CI environment)
371+
if _, err := exec.Command("docker", "info").CombinedOutput(); err != nil {
372+
b.Skip("Docker not available, skipping integration benchmark")
373+
}
374+
368375
tc := SetupTestContainer(&testing.T{})
369376
defer tc.Close(&testing.T{})
370377

@@ -384,6 +391,12 @@ func BenchmarkCheckPasswordForDN(b *testing.B) {
384391
if testing.Short() {
385392
b.Skip("Skipping integration benchmark in short mode")
386393
}
394+
395+
// Skip if Docker not available (CI environment)
396+
if _, err := exec.Command("docker", "info").CombinedOutput(); err != nil {
397+
b.Skip("Docker not available, skipping integration benchmark")
398+
}
399+
387400
tc := SetupTestContainer(&testing.T{})
388401
defer tc.Close(&testing.T{})
389402

cache_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"context"
77
"errors"
88
"fmt"
9+
"io"
10+
"log/slog"
911
"strings"
1012
"sync"
1113
"sync/atomic"
@@ -865,7 +867,9 @@ func BenchmarkLRUCacheSet(b *testing.B) {
865867
MaxSize: 10000,
866868
}
867869

868-
cache, err := NewLRUCache(config, nil)
870+
// Use discard logger to eliminate logging noise in benchmarks
871+
discardLogger := slog.New(slog.NewTextHandler(io.Discard, nil))
872+
cache, err := NewLRUCache(config, discardLogger)
869873
require.NoError(b, err)
870874
defer func() { _ = cache.Close() }()
871875

@@ -889,7 +893,9 @@ func BenchmarkLRUCacheGet(b *testing.B) {
889893
MaxSize: 10000,
890894
}
891895

892-
cache, err := NewLRUCache(config, nil)
896+
// Use discard logger to eliminate logging noise in benchmarks
897+
discardLogger := slog.New(slog.NewTextHandler(io.Discard, nil))
898+
cache, err := NewLRUCache(config, discardLogger)
893899
require.NoError(b, err)
894900
defer func() { _ = cache.Close() }()
895901

@@ -919,7 +925,9 @@ func BenchmarkCacheConcurrent(b *testing.B) {
919925
MaxSize: 10000,
920926
}
921927

922-
cache, err := NewLRUCache(config, nil)
928+
// Use discard logger to eliminate logging noise in benchmarks
929+
discardLogger := slog.New(slog.NewTextHandler(io.Discard, nil))
930+
cache, err := NewLRUCache(config, discardLogger)
923931
require.NoError(b, err)
924932
defer func() { _ = cache.Close() }()
925933

client_regression_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package ldap
55
import (
66
"context"
77
"errors"
8+
"io"
89
"log/slog"
910
"strings"
1011
"testing"
@@ -470,6 +471,7 @@ func BenchmarkRegressionCircuitBreaker(b *testing.B) {
470471
Timeout: 30 * time.Second,
471472
},
472473
},
474+
Logger: slog.New(slog.NewTextHandler(io.Discard, nil)), // Silent logger for benchmark
473475
}
474476

475477
client, err := New(*config, "user", "pass")

0 commit comments

Comments
 (0)