fix(acceptance): 清理中止验收的未提交任务
验收失败后,排队及尚未提交上游的任务会继续占用队列与 API 数据库连接池,导致下一轮容量测试被历史负载污染。 中止验收时仅取消确认未提交上游的任务,删除其未提交 attempt 与准入记录,释放租约并生成幂等退款事件;提交中或已收到上游响应的任务继续自然收敛。新建验收前也会清理历史失败 Run 的安全遗留任务,并等待其余任务终态。 验证:Go 全量测试通过;临时 PostgreSQL 集成测试覆盖排队、运行未提交、提交中与退款事件;gofmt、bash -n、ShellCheck、git diff --check 通过。
This commit is contained in:
@@ -218,6 +218,26 @@ wait_for_existing_tasks_to_drain() {
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_terminal_acceptance_tasks_to_drain() {
|
||||
local deadline=$((SECONDS + 300))
|
||||
local active
|
||||
while (( SECONDS < deadline )); do
|
||||
active=$(database_query "
|
||||
SELECT count(*)
|
||||
FROM gateway_tasks task
|
||||
JOIN gateway_acceptance_runs run ON run.id=task.acceptance_run_id
|
||||
WHERE run.status IN ('failed', 'aborted')
|
||||
AND task.status IN ('queued', 'running');")
|
||||
if [[ $active == 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
echo "waiting_for_terminal_acceptance_tasks=$active"
|
||||
sleep 2
|
||||
done
|
||||
echo "terminal acceptance tasks did not drain within 5 minutes: active=$active" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
ensure_acceptance_user_group() {
|
||||
local groups_response=$temporary_root/user-groups.json
|
||||
local group_response=$temporary_root/acceptance-user-group.json
|
||||
@@ -621,6 +641,7 @@ create_and_activate_run() {
|
||||
echo 'previous failed acceptance Run did not return traffic to live' >&2
|
||||
return 1
|
||||
}
|
||||
wait_for_terminal_acceptance_tasks_to_drain
|
||||
elif [[ $traffic_mode != live ]]; then
|
||||
echo "unsupported production traffic mode before acceptance: $traffic_mode" >&2
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user