perf(acceptance): 使用多钱包身份分片模拟并发

单一验收钱包会把预留和结算串行化,掩盖双节点 Worker 的真实吞吐。验收现在幂等准备 32 个隔离身份和钱包,按请求轮询 API Key,并在 Run 配置中登记允许的 Key/User 身份对;密钥仅经 stdin 传给集群内压测进程。\n\n仍保留真实账务、候选权限、回调、重复扣费和强杀恢复校验。\n\n验证:Go 全量测试、临时 PostgreSQL 集成测试、go vet、OpenAPI 生成、迁移安全检查、bash -n、ShellCheck。
This commit is contained in:
2026-07-31 04:25:09 +08:00
parent 8ce120631f
commit 262090db7b
6 changed files with 263 additions and 42 deletions
+21 -3
View File
@@ -583,17 +583,35 @@ func (s *Store) AuthorizeAcceptanceTask(ctx context.Context, runID string, token
return "", ErrAcceptanceNotAuthorized
}
var activeRunID, apiKeyID, userID, tokenHash, status string
var participantAuthorized bool
err = s.pool.QueryRow(ctx, `
SELECT id::text, api_key_id, user_id, token_sha256, status
SELECT id::text, api_key_id, user_id, token_sha256, status,
(
(api_key_id = $2 AND user_id = $3)
OR EXISTS (
SELECT 1
FROM jsonb_array_elements(
CASE
WHEN jsonb_typeof(config->'participants') = 'array'
THEN config->'participants'
ELSE '[]'::jsonb
END
) participant
WHERE participant->>'apiKeyId' = $2
AND participant->>'userId' = $3
)
)
FROM gateway_acceptance_runs
WHERE id = $1::uuid`, runID).Scan(&activeRunID, &apiKeyID, &userID, &tokenHash, &status)
WHERE id = $1::uuid`, runID, strings.TrimSpace(user.APIKeyID), strings.TrimSpace(user.ID)).Scan(
&activeRunID, &apiKeyID, &userID, &tokenHash, &status, &participantAuthorized,
)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return "", ErrAcceptanceNotAuthorized
}
return "", err
}
if status != "running" || apiKeyID != strings.TrimSpace(user.APIKeyID) || userID != strings.TrimSpace(user.ID) ||
if status != "running" || !participantAuthorized ||
subtle.ConstantTimeCompare([]byte(tokenHash), []byte(acceptanceTokenSHA256(token))) != 1 {
return "", ErrAcceptanceNotAuthorized
}