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
+16 -3
View File
@@ -53,9 +53,19 @@ func TestGeminiLoadIsSplitAcrossTwoGatewayAPIs(t *testing.T) {
encoded := base64.StdEncoding.EncodeToString(output)
var firstCalls atomic.Int64
var secondCalls atomic.Int64
var firstKeyCalls atomic.Int64
var secondKeyCalls atomic.Int64
newGateway := func(calls *atomic.Int64) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
calls.Add(1)
switch r.Header.Get("Authorization") {
case "Bearer key-1":
firstKeyCalls.Add(1)
case "Bearer key-2":
secondKeyCalls.Add(1)
default:
t.Errorf("unexpected authorization header")
}
if r.Header.Get(runHeader) != "run-1" || r.Header.Get(tokenHeader) != "token-1" {
t.Errorf("missing acceptance headers")
}
@@ -78,7 +88,7 @@ func TestGeminiLoadIsSplitAcrossTwoGatewayAPIs(t *testing.T) {
defer second.Close()
opts := options{
gateways: []string{first.URL, second.URL}, apiKey: "key-1", runID: "run-1",
gateways: []string{first.URL, second.URL}, apiKeys: []string{"key-1", "key-2"}, runID: "run-1",
runToken: "token-1", geminiModel: "gemini-image-test",
}
result := runGemini(t.Context(), http.DefaultClient, opts, "dual-api", 8, 256<<10, 256<<10, false)
@@ -88,6 +98,9 @@ func TestGeminiLoadIsSplitAcrossTwoGatewayAPIs(t *testing.T) {
if firstCalls.Load() != 4 || secondCalls.Load() != 4 {
t.Fatalf("gateway calls=%d/%d", firstCalls.Load(), secondCalls.Load())
}
if firstKeyCalls.Load() != 4 || secondKeyCalls.Load() != 4 {
t.Fatalf("API key calls=%d/%d", firstKeyCalls.Load(), secondKeyCalls.Load())
}
}
func TestValidateVideoAssetDownloadsFinalMedia(t *testing.T) {
@@ -117,10 +130,10 @@ func TestAcceptanceReportErrorRedactsSecretsAndURLs(t *testing.T) {
func TestAcceptanceGatewayTLSNameSetsHostHeader(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "https://127.0.0.1/api/v1/healthz", nil)
opts := options{
apiKey: "key-1", runID: "run-1", runToken: "token-1",
apiKeys: []string{"key-1"}, runID: "run-1", runToken: "token-1",
gatewayTLSName: "ai.example.com",
}
opts.setHeaders(request, false)
opts.setHeaders(request, 0, false)
if request.Host != "ai.example.com" {
t.Fatalf("Host=%q", request.Host)
}