25 lines
1.1 KiB
Go
25 lines
1.1 KiB
Go
package task
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestMethodExecutionOptionsPreservesImportedPolicy(t *testing.T) {
|
|
options, err := MethodExecutionOptions([]byte(`{"startDate":"2026-11-03","_execution":{"timeoutSeconds":1600,"maxRetryTimes":3,"retryIntervalSeconds":1}}`))
|
|
if err != nil || options.Timeout != 1600*time.Second || options.MaxRetryTimes != 3 || options.RetryInterval != time.Second {
|
|
t.Fatalf("迁移任务策略丢失: %+v %v", options, err)
|
|
}
|
|
for _, params := range []string{"", `{}`, `[]`, `"value"`} {
|
|
options, err := MethodExecutionOptions([]byte(params))
|
|
if err != nil || options.Timeout != 5*time.Minute || options.MaxRetryTimes != 0 {
|
|
t.Fatalf("普通方法默认行为变化: %q %+v %v", params, options, err)
|
|
}
|
|
}
|
|
for _, params := range []string{`{"_execution":{"timeoutSeconds":0}}`, `{"_execution":{"timeoutSeconds":86401}}`, `{"_execution":{"maxRetryTimes":11}}`, `{"_execution":{"retryIntervalSeconds":-1}}`, `{"_execution":"invalid"}`} {
|
|
if _, err := MethodExecutionOptions([]byte(params)); err == nil {
|
|
t.Fatalf("无效执行参数未拒绝: %s", params)
|
|
}
|
|
}
|
|
}
|