fix(routing): 额度饱和时解除任务候选固定
已取得并发租约的任务继续保持候选绑定;仅当已绑定平台的 RPM 或 TPM 已满且存在可用候选时,允许任务在执行前原子迁移到下一平台,避免等待窗口重置。\n\n验证:\n- go test ./internal/runner -count=1\n- go vet ./internal/runner
This commit is contained in:
@@ -227,6 +227,70 @@ func TestPinCandidatesToTaskAdmissionAllowsRequestedReselection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPinCandidatesToTaskAdmissionAllowsProviderRateQuotaMigration(t *testing.T) {
|
||||
input := []store.RuntimeModelCandidate{
|
||||
{
|
||||
PlatformID: "platform-b",
|
||||
PlatformModelID: "model-b",
|
||||
PlatformPriority: 200,
|
||||
LoadMetrics: store.RuntimeCandidateLoadMetrics{
|
||||
RPMLimit: 12,
|
||||
RPMCurrent: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
PlatformID: "platform-a",
|
||||
PlatformModelID: "model-a",
|
||||
PlatformPriority: 100,
|
||||
LoadAvoided: true,
|
||||
LoadMetrics: store.RuntimeCandidateLoadMetrics{
|
||||
RPMLimit: 4,
|
||||
RPMCurrent: 4,
|
||||
},
|
||||
},
|
||||
}
|
||||
admission := &store.TaskAdmission{
|
||||
Status: "admitted",
|
||||
PlatformID: "platform-a",
|
||||
PlatformModelID: "model-a",
|
||||
}
|
||||
|
||||
got, pinned := pinCandidatesToTaskAdmission(input, admission)
|
||||
|
||||
if pinned {
|
||||
t.Fatalf("rate-full provider remained pinned: %+v", got)
|
||||
}
|
||||
if got[0].PlatformModelID != "model-b" {
|
||||
t.Fatalf("available fallback was not preserved: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPinCandidatesToTaskAdmissionKeepsConcurrencyLeaseBinding(t *testing.T) {
|
||||
input := []store.RuntimeModelCandidate{
|
||||
{PlatformID: "platform-b", PlatformModelID: "model-b"},
|
||||
{
|
||||
PlatformID: "platform-a",
|
||||
PlatformModelID: "model-a",
|
||||
LoadAvoided: true,
|
||||
LoadMetrics: store.RuntimeCandidateLoadMetrics{
|
||||
ConcurrentLimit: 2,
|
||||
ConcurrentCurrent: 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
admission := &store.TaskAdmission{
|
||||
Status: "admitted",
|
||||
PlatformID: "platform-a",
|
||||
PlatformModelID: "model-a",
|
||||
}
|
||||
|
||||
got, pinned := pinCandidatesToTaskAdmission(input, admission)
|
||||
|
||||
if !pinned || got[0].PlatformModelID != "model-a" {
|
||||
t.Fatalf("valid concurrency lease binding was not preserved: pinned=%v candidates=%+v", pinned, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPinCandidatesToTaskAdmissionIgnoresMissingCandidate(t *testing.T) {
|
||||
input := []store.RuntimeModelCandidate{
|
||||
{PlatformID: "platform-a", PlatformModelID: "model-a"},
|
||||
|
||||
Reference in New Issue
Block a user