@@ -39,14 +39,46 @@ import (
3939// static check to ensure Plugin implements the PrepareDataPlugin interface.
4040var _ requestcontrol.PrepareDataPlugin = & Plugin {}
4141
42+ func TestPrefixPluginValidation (t * testing.T ) {
43+ validConfigs := []Config {{
44+ AutoTune : false ,
45+ BlockSizeTokens : 1 ,
46+ MaxPrefixBlocksToMatch : DefaultMaxPrefixBlocks ,
47+ LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
48+ }, {
49+ AutoTune : false ,
50+ BlockSize : 1 ,
51+ BlockSizeTokens : 1 ,
52+ MaxPrefixBlocksToMatch : DefaultMaxPrefixBlocks ,
53+ LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
54+ }}
55+ invalidConfigs := []Config {{
56+ AutoTune : false ,
57+ BlockSize : 1 ,
58+ MaxPrefixBlocksToMatch : DefaultMaxPrefixBlocks ,
59+ LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
60+ }}
61+
62+ for _ , config := range validConfigs {
63+ _ , err := New (context .Background (), config )
64+ assert .NoError (t , err )
65+ }
66+
67+ for _ , config := range invalidConfigs {
68+ _ , err := New (context .Background (), config )
69+ assert .Error (t , err )
70+ }
71+ }
72+
4273func TestPrefixPluginCompletion (t * testing.T ) {
4374 config := Config {
4475 AutoTune : false ,
4576 BlockSizeTokens : 1 ,
4677 MaxPrefixBlocksToMatch : DefaultMaxPrefixBlocks ,
4778 LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
4879 }
49- plugin := New (context .Background (), config )
80+ plugin , err := New (context .Background (), config )
81+ assert .NoError (t , err )
5082
5183 pod1 := & types.PodMetrics {Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}, MetricsState : backendmetrics .NewMetricsState ()}
5284 pod2 := & types.PodMetrics {Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}, MetricsState : backendmetrics .NewMetricsState ()}
@@ -212,7 +244,8 @@ func TestPrefixPluginChatCompletions(t *testing.T) {
212244 MaxPrefixBlocksToMatch : DefaultMaxPrefixBlocks ,
213245 LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
214246 }
215- plugin := New (context .Background (), config )
247+ plugin , err := New (context .Background (), config )
248+ assert .NoError (t , err )
216249
217250 pod1 := & types.PodMetrics {Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}, MetricsState : & backendmetrics.MetricsState {}}
218251 pods := []types.Pod {pod1 }
@@ -247,7 +280,8 @@ func TestPrefixPluginChatCompletionsGrowth(t *testing.T) {
247280 MaxPrefixBlocksToMatch : DefaultMaxPrefixBlocks ,
248281 LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
249282 }
250- plugin := New (context .Background (), config )
283+ plugin , err := New (context .Background (), config )
284+ assert .NoError (t , err )
251285
252286 pod1 := & types.PodMetrics {Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}, MetricsState : & backendmetrics.MetricsState {}}
253287 pod2 := & types.PodMetrics {Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}, MetricsState : & backendmetrics.MetricsState {}}
@@ -361,7 +395,8 @@ func BenchmarkPrefixPluginStress(b *testing.B) {
361395 LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
362396 }
363397
364- plugin := New (context .Background (), config )
398+ plugin , err := New (context .Background (), config )
399+ assert .NoError (b , err )
365400 types .NewCycleState ()
366401 var promptLen []int
367402 for i := 1 ; i <= 1024 ; {
@@ -462,8 +497,9 @@ func TestNew_InvalidConfigFallbacks(t *testing.T) {
462497 for _ , tt := range tests {
463498 t .Run (tt .name , func (t * testing.T ) {
464499
465- plugin := New (context .Background (), tt .config )
500+ plugin , err := New (context .Background (), tt .config )
466501
502+ assert .NoError (t , err )
467503 assert .NotEmpty (t , plugin )
468504 assert .NotEmpty (t , plugin .indexer )
469505 assert .Equal (t , tt .expectBlock , plugin .config .BlockSizeTokens )
@@ -506,7 +542,8 @@ func TestPrefixPluginAutoTune(t *testing.T) {
506542 // Should be ignored in favor of pod metrics (1000)
507543 LRUCapacityPerServer : 1 ,
508544 }
509- plugin := New (context .Background (), config )
545+ plugin , err := New (context .Background (), config )
546+ assert .NoError (t , err )
510547
511548 // 1. Verify Score uses pod metrics for block size
512549 scores := plugin .Score (context .Background (), types .NewCycleState (), req , pods )
@@ -540,7 +577,8 @@ func TestPrefixPluginAutoTune(t *testing.T) {
540577 MaxPrefixBlocksToMatch : DefaultMaxPrefixBlocks ,
541578 LRUCapacityPerServer : 1 , // Should be used, and the first hash should be evicted due to the small
542579 }
543- plugin := New (context .Background (), config )
580+ plugin , err := New (context .Background (), config )
581+ assert .NoError (t , err )
544582
545583 // 1. Verify Score uses config BlockSize
546584 req .RequestId = uuid .NewString () // New request ID
@@ -584,7 +622,8 @@ func TestPrepareRequestData(t *testing.T) {
584622 MaxPrefixBlocksToMatch : DefaultMaxPrefixBlocks ,
585623 LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
586624 }
587- plugin := New (context .Background (), config )
625+ plugin , err := New (context .Background (), config )
626+ assert .NoError (t , err )
588627
589628 pod1 := & types.PodMetrics {Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}, MetricsState : backendmetrics .NewMetricsState (), AttributeMap : datalayer .NewAttributes ()}
590629 pod2 := & types.PodMetrics {Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}, MetricsState : backendmetrics .NewMetricsState (), AttributeMap : datalayer .NewAttributes ()}
@@ -621,7 +660,7 @@ func TestPrepareRequestData(t *testing.T) {
621660 },
622661 }
623662
624- err : = plugin .PrepareRequestData (context .Background (), req2 , pods )
663+ err = plugin .PrepareRequestData (context .Background (), req2 , pods )
625664 assert .NoError (t , err )
626665
627666 // Verify pod1 has the correct prefix match info
@@ -647,7 +686,8 @@ func BenchmarkPrefixPluginChatCompletionsStress(b *testing.B) {
647686 MaxPrefixBlocksToMatch : maxPrefixBlocks ,
648687 LRUCapacityPerServer : DefaultLRUCapacityPerServer ,
649688 }
650- plugin := New (context .Background (), config )
689+ plugin , err := New (context .Background (), config )
690+ assert .NoError (b , err )
651691
652692 // Test scenarios: varying number of messages and message lengths
653693 scenarios := []struct {
0 commit comments