完善P0-10任务并发与恢复保护
补齐幂等活动状态、管理证书并发保护、服务重启尝试范围保护及对应回归测试。
This commit is contained in:
1 parent
569499e54d
commit
402d282022
5 files changed
+89
-19
No files matched your search
@@ -432,21 +432,14 @@ func validTaskIdempotencyKey(value string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isActiveTaskStatus(status string) bool {
|
||||
|
||||
switch status {
|
||||
|
||||
case "queued", "running", "retry_wait", "cancelling":
|
||||
|
||||
|
||||
return true
|
||||
|
||||
default:
|
||||
|
||||
|
||||
return false
|
||||
|
||||
}
|
||||
switch status {
|
||||
case "queued", "running", "retry_wait", "cancelling":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) listTasks(c *gin.Context) {
|
||||
|
||||
@@ -394,6 +394,33 @@ func TestTaskAPIReplaysIdempotentIssue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskAPIRejectsIdempotentIssueForAllActiveStatuses(t *testing.T) {
|
||||
server, taskRepo, _, closeDB := newTaskAPITestServer(t, func(context.Context, string) (certificate.IssueResult, deployment.Report, error) {
|
||||
t.Fatal("活动幂等任务不应重复执行证书申请")
|
||||
return certificate.IssueResult{}, deployment.Report{}, nil
|
||||
})
|
||||
defer closeDB()
|
||||
|
||||
for _, status := range []string{"retry_wait", "cancelling"} {
|
||||
key := "issue-active-" + status
|
||||
task := repository.Task{
|
||||
HistoryScope: repository.HistoryScope{ScopeType: repository.ScopeProject, ProjectID: domain.DefaultProjectID},
|
||||
ID: "task-active-" + status, DomainID: "domain-1", TaskType: "certificate_issue",
|
||||
Status: status, Stage: "certificate_issue", IdempotencyKey: key,
|
||||
}
|
||||
if err := taskRepo.CreateTask(t.Context(), task); err != nil {
|
||||
t.Fatalf("创建%s幂等任务失败:%v", status, err)
|
||||
}
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/domains/domain-1/issue", nil)
|
||||
request.Header.Set("Idempotency-Key", key)
|
||||
response := httptest.NewRecorder()
|
||||
serveAdminHTTP(server, response, request)
|
||||
if response.Code != http.StatusConflict || !strings.Contains(response.Body.String(), task.ID) {
|
||||
t.Fatalf("%s幂等任务应返回冲突:%d %s", status, response.Code, response.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskAPIReturnsNotImplementedWhenTaskDependenciesAreMissing(t *testing.T) {
|
||||
cfg := readyTestConfig(t.TempDir())
|
||||
server := New(Dependencies{
|
||||
|
||||
Reference in new issue
Block a user