fix(backend): PR 合并治理 - 限制轮询并收敛模型目录事务

This commit is contained in:
ddCat committed 2026-09-07 15:41:37 +08:00
1 parent 550149cbff
commit d4f3a7e7d3
6 files changed
+91 -39

No files matched your search

@@ -31,7 +31,8 @@ func TestOnlyResumableNewAPIChannel2VideoDeadlinesStayRunning(t *testing.T) {
if err != nil {
t.Fatal(err)
}
base := model.Task{ID: "task-1", Type: "canvas_video", ProviderRequestID: "provider-task-1"}
startedAt := time.Now()
base := model.Task{ID: "task-1", Type: "canvas_video", ProviderRequestID: "provider-task-1", StartedAt: &startedAt}
if !svc.shouldDeferVideoProviderTask(base, string(input), context.DeadlineExceeded) {
t.Fatal("resumable NewAPI Channel 2 deadline should remain running")
}
@@ -39,6 +40,17 @@ func TestOnlyResumableNewAPIChannel2VideoDeadlinesStayRunning(t *testing.T) {
if !svc.shouldDeferVideoProviderTask(base, string(input), pendingErr) {
t.Fatal("resumable NewAPI Channel 2 provider sync delay should remain running")
}
expiredStartedAt := startedAt.Add(-newAPIChannel2TaskSyncMaxAge - time.Second)
expiredTask := model.Task{ID: base.ID, Type: base.Type, ProviderRequestID: base.ProviderRequestID, StartedAt: &expiredStartedAt}
if svc.shouldDeferVideoProviderTask(expiredTask, string(input), pendingErr) {
t.Fatal("provider sync delay must stop after the bounded synchronization window")
}
if !svc.shouldDeferVideoProviderTask(expiredTask, string(input), context.DeadlineExceeded) {
t.Fatal("a normal long-running provider task must remain resumable after the synchronization window")
}
if svc.shouldDeferVideoProviderTask(model.Task{ID: base.ID, Type: base.Type, ProviderRequestID: base.ProviderRequestID}, string(input), pendingErr) {
t.Fatal("provider sync delay without a persisted start time must fail closed")
}
if svc.shouldDeferVideoProviderTask(model.Task{ID: "task-2", Type: "canvas_video"}, string(input), context.DeadlineExceeded) {
t.Fatal("missing provider task id must not be deferred")
}