@@ -52,8 +52,8 @@ func TestPrefixPlugin(t *testing.T) {
5252 TargetModel : "test-model1" ,
5353 Prompt : "aaaaaa" ,
5454 }
55- scores := plugin .Score (context .Background (), nil , req1 , pods )
56- state , err := plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req1 .RequestId , PrefixCachePluginType )
55+ scores := plugin .Score (context .Background (), types . NewCycleState () , req1 , pods )
56+ state , err := plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req1 .RequestId , plugins . StateKey ( plugin . TypedName (). String ()) )
5757 assert .NoError (t , err )
5858 t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
5959 // Input size is 6, hash block size is 4, the last 2 characters are ignored.
@@ -79,8 +79,8 @@ func TestPrefixPlugin(t *testing.T) {
7979 TargetModel : "test-model2" ,
8080 Prompt : "bbbbbb" ,
8181 }
82- scores = plugin .Score (context .Background (), nil , req2 , pods )
83- state , err = plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req2 .RequestId , PrefixCachePluginType )
82+ scores = plugin .Score (context .Background (), types . NewCycleState () , req2 , pods )
83+ state , err = plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req2 .RequestId , plugins . StateKey ( plugin . TypedName (). String ()) )
8484 assert .NoError (t , err )
8585 t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
8686 // Input size is 6, hash block size is 4, the last 2 characters are ignored.
@@ -105,8 +105,8 @@ func TestPrefixPlugin(t *testing.T) {
105105 TargetModel : "test-model1" ,
106106 Prompt : "aaaabbbb" ,
107107 }
108- scores = plugin .Score (context .Background (), nil , req3 , pods )
109- state , err = plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req3 .RequestId , PrefixCachePluginType )
108+ scores = plugin .Score (context .Background (), types . NewCycleState () , req3 , pods )
109+ state , err = plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req3 .RequestId , plugins . StateKey ( plugin . TypedName (). String ()) )
110110 assert .NoError (t , err )
111111 t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
112112 // Input size is 8, hash block size is 4, so 2 hashes will be calculated.
@@ -130,8 +130,8 @@ func TestPrefixPlugin(t *testing.T) {
130130 TargetModel : "test-model-new" ,
131131 Prompt : "aaaabbbb" ,
132132 }
133- scores = plugin .Score (context .Background (), nil , req4 , pods )
134- state , err = plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req4 .RequestId , PrefixCachePluginType )
133+ scores = plugin .Score (context .Background (), types . NewCycleState () , req4 , pods )
134+ state , err = plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req4 .RequestId , plugins . StateKey ( plugin . TypedName (). String ()) )
135135 assert .NoError (t , err )
136136 t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
137137 // Input size is 8, hash block size is 4, so 2 hashes will be calculated.
@@ -155,8 +155,8 @@ func TestPrefixPlugin(t *testing.T) {
155155 TargetModel : "test-model1" ,
156156 Prompt : "aaaabbbbcccc" ,
157157 }
158- scores = plugin .Score (context .Background (), nil , req5 , pods )
159- state , err = plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req5 .RequestId , PrefixCachePluginType )
158+ scores = plugin .Score (context .Background (), types . NewCycleState () , req5 , pods )
159+ state , err = plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req5 .RequestId , plugins . StateKey ( plugin . TypedName (). String ()) )
160160 assert .NoError (t , err )
161161 t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
162162 // Input size is 12, hash block size is 4, so 3 hashes will be calculated.
@@ -212,7 +212,7 @@ func BenchmarkPrefixPluginStress(b *testing.B) {
212212 }
213213
214214 // First cycle: simulate scheduling and insert prefix info into the cache
215- plugin .Score (context .Background (), nil , req , pods )
215+ plugin .Score (context .Background (), types . NewCycleState () , req , pods )
216216 schedulingResult := & types.SchedulingResult {
217217 PrimaryProfileName : "default" ,
218218 ProfileResults : map [string ]* types.ProfileRunResult {
@@ -222,7 +222,7 @@ func BenchmarkPrefixPluginStress(b *testing.B) {
222222 plugin .PreRequest (context .Background (), req , schedulingResult , 0 )
223223
224224 // Second cycle: validate internal state
225- state , err := plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req .RequestId , PrefixCachePluginType )
225+ state , err := plugins .ReadPluginStateKey [* SchedulingContextState ](plugin .pluginState , req .RequestId , plugins . StateKey ( plugin . TypedName (). String ()) )
226226 assert .NoError (b , err )
227227 expectedHashes := int (math .Min (float64 (maxPrefixBlocks ), float64 (len (req .Prompt )/ blockSize )))
228228 assert .Equal (b , expectedHashes , len (state .PrefixHashes ), "number of hashes is incorrect" )
0 commit comments