39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package runner
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
|
)
|
|
|
|
func TestAttemptMetricsIncludesCacheAffinityCoefficient(t *testing.T) {
|
|
metrics := attemptMetrics(store.RuntimeModelCandidate{
|
|
ModelName: "deepseek-chat",
|
|
ModelType: "text_generate",
|
|
PlatformID: "deepseek-platform",
|
|
PlatformPriority: 100,
|
|
CacheAffinity: store.RuntimeCandidateCacheAffinity{
|
|
Key: "conversation:test",
|
|
RequestCount: 2,
|
|
CachedInputTokens: 7296,
|
|
EMAHitRatio: 0.91,
|
|
LastHitRatio: 0.92,
|
|
Confidence: 1,
|
|
Score: 1.74,
|
|
Boost: 20,
|
|
AdjustedPriority: 80,
|
|
Applied: true,
|
|
},
|
|
}, 1, false)
|
|
|
|
if metrics["cacheAffinityScore"] != 1.74 {
|
|
t.Fatalf("expected cache affinity score in attempt metrics, got %+v", metrics)
|
|
}
|
|
if metrics["cacheAffinityCachedInputTokens"] != 7296 {
|
|
t.Fatalf("expected cached input tokens in attempt metrics, got %+v", metrics)
|
|
}
|
|
if metrics["cacheAffinityHitRatio"] != 0.91 || metrics["cacheAffinityLastHitRatio"] != 0.92 {
|
|
t.Fatalf("expected hit ratios in attempt metrics, got %+v", metrics)
|
|
}
|
|
}
|