@@ -59,25 +59,26 @@ func TestPrefixPluginScoreWithWeights(t *testing.T) {
5959
6060 key := attrprefix .PrefixCacheMatchInfoDataKey .WithNonEmptyProducerName (producerName ).String ()
6161
62- // Endpoint 1: match 50 , total 80 , block size 1
63- // matchRatio = 50/80 = 0.625
64- // matchLengthRatio = 80 *1/100 = 0.8 -> squared = 0.64
65- // score = 0.5 * 0.64 + 0.5 * 0.625 = 0.6325
62+ // Endpoint 1: match 5 , total 10 , block size 1
63+ // matchRatio = 5/10 = 0.5
64+ // matchLengthRatio = min(1.0, 5 *1/100) = 0.05 -> squared = 0.0025
65+ // score = 0.5 * 0.0025 + 0.5 * 0.5 = 0.25125
6666 endpoint1 := fwksched .NewEndpoint (& fwkdl.EndpointMetadata {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }}, fwkdl .NewMetrics (), nil )
67- endpoint1 .Put (key , attrprefix .NewPrefixCacheMatchInfo (50 , 80 , 1 ))
67+ endpoint1 .Put (key , attrprefix .NewPrefixCacheMatchInfo (5 , 10 , 1 ))
6868
69- // Endpoint 2: match 10 , total 200 , block size 1 (exceeds maxModelLen)
70- // matchRatio = 10/200 = 0.05
71- // matchLengthRatio = 200 *1/100 = 2.0 -> squared = 4.0 -> capped at 1.0
72- // score = 0.5 * 1.0 + 0.5 * 0.05 = 0.525
69+ // Endpoint 2: match 50 , total 100 , block size 1
70+ // matchRatio = 50/100 = 0.5
71+ // matchLengthRatio = min(1.0, 50 *1/100) = 0.5 -> squared = 0.25
72+ // score = 0.5 * 0.25 + 0.5 * 0.5 = 0.375
7373 endpoint2 := fwksched .NewEndpoint (& fwkdl.EndpointMetadata {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }}, fwkdl .NewMetrics (), nil )
74- endpoint2 .Put (key , attrprefix .NewPrefixCacheMatchInfo (10 , 200 , 1 ))
74+ endpoint2 .Put (key , attrprefix .NewPrefixCacheMatchInfo (50 , 100 , 1 ))
7575
7676 endpoints := []fwksched.Endpoint {endpoint1 , endpoint2 }
7777 scores := p .Score (context .Background (), nil , endpoints )
7878
79- assert .InDelta (t , 0.6325 , scores [endpoint1 ], 1e-6 )
80- assert .InDelta (t , 0.525 , scores [endpoint2 ], 1e-6 )
79+ // matchRatio is the same but we still give longer request higher score
80+ assert .InDelta (t , 0.25125 , scores [endpoint1 ], 1e-6 )
81+ assert .InDelta (t , 0.375 , scores [endpoint2 ], 1e-6 )
8182}
8283
8384func TestPrefixPluginFactoryValidation (t * testing.T ) {
0 commit comments