@@ -3,8 +3,38 @@ package metrics
33import (
44 "testing"
55 "time"
6+
7+ "github.com/vllm-project/semantic-router/semantic-router/pkg/config"
68)
79
10+ // TestMain ensures metrics are initialized before running tests
11+ func TestMain (m * testing.M ) {
12+ // Initialize metrics with default configuration for testing
13+ config := BatchMetricsConfig {
14+ Enabled : true ,
15+ DetailedGoroutineTracking : true ,
16+ HighResolutionTiming : false ,
17+ SampleRate : 1.0 ,
18+ DurationBuckets : FallbackDurationBuckets ,
19+ SizeBuckets : FallbackSizeBuckets ,
20+ BatchSizeRanges : []config.BatchSizeRangeConfig {
21+ {Min : 1 , Max : 1 , Label : "1" },
22+ {Min : 2 , Max : 5 , Label : "2-5" },
23+ {Min : 6 , Max : 10 , Label : "6-10" },
24+ {Min : 11 , Max : 20 , Label : "11-20" },
25+ {Min : 21 , Max : 50 , Label : "21-50" },
26+ {Min : 51 , Max : - 1 , Label : "50+" },
27+ },
28+ }
29+
30+ // Initialize batch metrics
31+ InitializeBatchMetrics (config )
32+ SetBatchMetricsConfig (config )
33+
34+ // Run tests
35+ m .Run ()
36+ }
37+
838// TestBatchClassificationMetrics tests the batch classification metrics recording
939func TestBatchClassificationMetrics (t * testing.T ) {
1040 tests := []struct {
@@ -52,10 +82,6 @@ func TestBatchClassificationMetrics(t *testing.T) {
5282 if tt .expectError {
5383 RecordBatchClassificationError (tt .processingType , tt .errorType )
5484 }
55-
56- // Test passes if no panic occurs during metric recording
57- // In a real production environment, you would verify the actual metric values
58- // using prometheus test utilities or by checking the metric registry
5985 })
6086 }
6187}
@@ -97,9 +123,6 @@ func TestConcurrentGoroutineTracking(t *testing.T) {
97123
98124 // Simulate goroutine end
99125 ConcurrentGoroutines .WithLabelValues (batchID ).Dec ()
100-
101- // Test passes if no panic occurs during goroutine tracking
102- // In production, you would verify the gauge values
103126}
104127
105128// BenchmarkBatchClassificationMetrics benchmarks the performance impact of metrics recording
@@ -142,6 +165,4 @@ func TestMetricsIntegration(t *testing.T) {
142165 for i := 0 ; i < batchSize ; i ++ {
143166 ConcurrentGoroutines .WithLabelValues (batchID ).Dec ()
144167 }
145-
146- // Test passes if no panic occurs during the complete workflow
147168}
0 commit comments