实现本地三节点 K3s 同构环境、脱敏生产快照、Gemini 图片和多参考图视频协议模拟、统一验收报告及故障注入。\n\n新增 Worker 容量控制器、资源与连接预算、任务恢复保护,并将生产验收拆分为 validation 执行和人工 CAS 放量。\n\n验证包括 Go 全量测试、PostgreSQL HTTP 集成测试、go vet、OpenAPI、ShellCheck、前端检查、迁移及发布脚本测试。
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package store
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestCapacityKindForTask(t *testing.T) {
|
|
tests := map[string]string{
|
|
"images.generations": "image",
|
|
"images.edits": "image",
|
|
"images.vectorize": "image",
|
|
"videos.generations": "video",
|
|
"videos.upscales": "video",
|
|
"chat.completions": "",
|
|
}
|
|
for taskKind, expected := range tests {
|
|
if actual := capacityKindForTask(taskKind); actual != expected {
|
|
t.Fatalf("capacityKindForTask(%q)=%q, want %q", taskKind, actual, expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCapacityProfileValidationAndStableHash(t *testing.T) {
|
|
profiles := []CapacityProfileInput{
|
|
{
|
|
Kind: "image", Model: "gemini-image",
|
|
StableThroughputPerSecond: 10, AdmittedThroughputPerSecond: 8,
|
|
MaxRunning: 48, MaxQueued: 100, MaxPredictedWaitSeconds: 60,
|
|
Metadata: map[string]any{"profile": "P24"},
|
|
},
|
|
{
|
|
Kind: "video", Model: "seedance",
|
|
StableThroughputPerSecond: 2, AdmittedThroughputPerSecond: 1.6,
|
|
MaxRunning: 48, MaxQueued: 100, MaxPredictedWaitSeconds: 120,
|
|
},
|
|
}
|
|
if err := validateCapacityProfileInputs(profiles); err != nil {
|
|
t.Fatalf("valid profiles were rejected: %v", err)
|
|
}
|
|
firstHash := capacityProfileInputsHash(profiles)
|
|
secondHash := capacityProfileInputsHash(profiles)
|
|
if len(firstHash) != 64 || firstHash != secondHash {
|
|
t.Fatalf("capacity profile hash is unstable: %q %q", firstHash, secondHash)
|
|
}
|
|
duplicate := append([]CapacityProfileInput(nil), profiles...)
|
|
duplicate = append(duplicate, profiles[0])
|
|
if err := validateCapacityProfileInputs(duplicate); err == nil || !strings.Contains(err.Error(), "duplicate") {
|
|
t.Fatalf("duplicate profiles validation error=%v", err)
|
|
}
|
|
}
|