fix: 完成商务迁移复核与接口优化并清理历史资料

This commit is contained in:
Yvan
2026-11-04 14:45:02 +08:00
parent 5a96be6a79
commit 297e80827d
176 changed files with 6803 additions and 6002 deletions
+43
View File
@@ -52,6 +52,49 @@ func TestRunMethodConvertsPanicToError(t *testing.T) {
}
}
func TestRunMethodUsesImportedDeadlineAndRetries(t *testing.T) {
registry := platformtask.NewRegistry()
attempts := 0
registry.Register(platformtask.Method{Name: "migrated-retry", Run: func(ctx context.Context, _ json.RawMessage) error {
attempts++
deadline, ok := ctx.Deadline()
if !ok || time.Until(deadline) < 1590*time.Second || time.Until(deadline) > 1600*time.Second {
return errors.New("迁移的 1600 秒超时未生效")
}
if attempts < 3 {
return errors.New("temporary")
}
return nil
}})
executor := &TaskExecutor{methods: registry}
task := &taskbiz.TimedTask{MethodName: "migrated-retry", Params: []byte(`{"_execution":{"timeoutSeconds":1600,"maxRetryTimes":3,"retryIntervalSeconds":0}}`)}
if err := executor.runMethod(context.Background(), task); err != nil || attempts != 3 {
t.Fatalf("迁移重试未生效: attempts=%d err=%v", attempts, err)
}
}
func TestRunMethodCancellationStopsRetryDelay(t *testing.T) {
registry := platformtask.NewRegistry()
started := make(chan struct{})
registry.Register(platformtask.Method{Name: "cancel-retry", Run: func(context.Context, json.RawMessage) error { close(started); return errors.New("temporary") }})
executor := &TaskExecutor{methods: registry}
ctx, cancel := context.WithCancel(context.Background())
done := make(chan error, 1)
go func() {
done <- executor.runMethod(ctx, &taskbiz.TimedTask{MethodName: "cancel-retry", Params: []byte(`{"_execution":{"maxRetryTimes":3,"retryIntervalSeconds":60}}`)})
}()
<-started
cancel()
select {
case err := <-done:
if !errors.Is(err, context.Canceled) {
t.Fatalf("取消重试错误: %v", err)
}
case <-time.After(time.Second):
t.Fatal("重试等待没有响应取消")
}
}
func TestRunMethodUsesParentContext(t *testing.T) {
const methodName = "worker-test-parent-context"
started := make(chan struct{})