fix(worker): 固定等待任务的准入候选
双 Worker 会按动态运行态排序重复规划同一批 waiting 任务,导致候选绑定来回迁移并把同步事务消耗在 rebind 上。\n\n调度 waiting 任务时优先使用首次登记的候选;仅当候选不再可用或已不在合法候选集时才按现有顺序迁移。执行阶段的 admitted 候选固定逻辑保持不变。\n\n验证:新增 waiting 候选固定回归测试;Go 全量测试、go vet、gofmt 通过。
This commit is contained in:
@@ -87,31 +87,41 @@ func TestPinCandidatesToTaskAdmissionPreservesAdmittedCandidate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPinCandidatesToTaskAdmissionIgnoresWaitingOrMissingCandidate(t *testing.T) {
|
||||
func TestPinCandidatesToTaskAdmissionPreservesWaitingCandidate(t *testing.T) {
|
||||
input := []store.RuntimeModelCandidate{
|
||||
{PlatformID: "platform-a", PlatformModelID: "model-a"},
|
||||
{PlatformID: "platform-b", PlatformModelID: "model-b"},
|
||||
}
|
||||
for name, admission := range map[string]*store.TaskAdmission{
|
||||
"waiting": {
|
||||
Status: "waiting",
|
||||
PlatformID: "platform-b",
|
||||
PlatformModelID: "model-b",
|
||||
},
|
||||
"missing": {
|
||||
Status: "admitted",
|
||||
PlatformID: "platform-c",
|
||||
PlatformModelID: "model-c",
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got, pinned := pinCandidatesToTaskAdmission(input, admission)
|
||||
if pinned {
|
||||
t.Fatalf("unexpected candidate pin for %s: %+v", name, got)
|
||||
}
|
||||
if got[0].PlatformModelID != "model-a" {
|
||||
t.Fatalf("candidate order changed for %s: %+v", name, got)
|
||||
}
|
||||
})
|
||||
admission := &store.TaskAdmission{
|
||||
Status: "waiting",
|
||||
PlatformID: "platform-b",
|
||||
PlatformModelID: "model-b",
|
||||
}
|
||||
|
||||
got, pinned := pinCandidatesToTaskAdmission(input, admission)
|
||||
|
||||
if !pinned || got[0].PlatformModelID != "model-b" {
|
||||
t.Fatalf("waiting candidate was not pinned: pinned=%v candidates=%+v", pinned, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPinCandidatesToTaskAdmissionIgnoresMissingCandidate(t *testing.T) {
|
||||
input := []store.RuntimeModelCandidate{
|
||||
{PlatformID: "platform-a", PlatformModelID: "model-a"},
|
||||
{PlatformID: "platform-b", PlatformModelID: "model-b"},
|
||||
}
|
||||
admission := &store.TaskAdmission{
|
||||
Status: "admitted",
|
||||
PlatformID: "platform-c",
|
||||
PlatformModelID: "model-c",
|
||||
}
|
||||
|
||||
got, pinned := pinCandidatesToTaskAdmission(input, admission)
|
||||
|
||||
if pinned {
|
||||
t.Fatalf("unexpected candidate pin for missing binding: %+v", got)
|
||||
}
|
||||
if got[0].PlatformModelID != "model-a" {
|
||||
t.Fatalf("candidate order changed for missing binding: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user