@@ -52,8 +52,8 @@ func TestPrefixPlugin(t *testing.T) {
52
52
TargetModel : "test-model1" ,
53
53
Prompt : "aaaaaa" ,
54
54
}
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 ()) )
57
57
assert .NoError (t , err )
58
58
t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
59
59
// Input size is 6, hash block size is 4, the last 2 characters are ignored.
@@ -79,8 +79,8 @@ func TestPrefixPlugin(t *testing.T) {
79
79
TargetModel : "test-model2" ,
80
80
Prompt : "bbbbbb" ,
81
81
}
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 ()) )
84
84
assert .NoError (t , err )
85
85
t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
86
86
// Input size is 6, hash block size is 4, the last 2 characters are ignored.
@@ -105,8 +105,8 @@ func TestPrefixPlugin(t *testing.T) {
105
105
TargetModel : "test-model1" ,
106
106
Prompt : "aaaabbbb" ,
107
107
}
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 ()) )
110
110
assert .NoError (t , err )
111
111
t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
112
112
// Input size is 8, hash block size is 4, so 2 hashes will be calculated.
@@ -130,8 +130,8 @@ func TestPrefixPlugin(t *testing.T) {
130
130
TargetModel : "test-model-new" ,
131
131
Prompt : "aaaabbbb" ,
132
132
}
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 ()) )
135
135
assert .NoError (t , err )
136
136
t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
137
137
// Input size is 8, hash block size is 4, so 2 hashes will be calculated.
@@ -155,8 +155,8 @@ func TestPrefixPlugin(t *testing.T) {
155
155
TargetModel : "test-model1" ,
156
156
Prompt : "aaaabbbbcccc" ,
157
157
}
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 ()) )
160
160
assert .NoError (t , err )
161
161
t .Logf ("Hashes %+v, cached servers: %+v" , state .PrefixHashes , state .PrefixCacheServers )
162
162
// Input size is 12, hash block size is 4, so 3 hashes will be calculated.
@@ -212,7 +212,7 @@ func BenchmarkPrefixPluginStress(b *testing.B) {
212
212
}
213
213
214
214
// 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 )
216
216
schedulingResult := & types.SchedulingResult {
217
217
PrimaryProfileName : "default" ,
218
218
ProfileResults : map [string ]* types.ProfileRunResult {
@@ -222,7 +222,7 @@ func BenchmarkPrefixPluginStress(b *testing.B) {
222
222
plugin .PreRequest (context .Background (), req , schedulingResult , 0 )
223
223
224
224
// 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 ()) )
226
226
assert .NoError (b , err )
227
227
expectedHashes := int (math .Min (float64 (maxPrefixBlocks ), float64 (len (req .Prompt )/ blockSize )))
228
228
assert .Equal (b , expectedHashes , len (state .PrefixHashes ), "number of hashes is incorrect" )
0 commit comments