保留平台模型 RPM、TPM 和并发策略语义,增加 PostgreSQL 集群级租约、饱和候选重选和多平台自动负载,避免突发任务固定等待首个平台。\n\n新增 Worker 实时负载采样、自适应 active/heavy 容量、心跳与管理端指标,并扩展本地 acceptance runner,覆盖三 Worker、同模型三平台 2/4/6 并发和 48 个带图视频突发任务。\n\n验证:go test ./...、go vet ./...、PostgreSQL 跨 Store 集成测试、gofmt、bash -n、ShellCheck 及本地集群 provider-burst 验收通过;48/48 成功,无越限、重复提交、重复计费、重复回调或终态资源泄漏。
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package workerload
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestSystemSamplerReadsCgroupV2(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeSamplerFixture(t, filepath.Join(root, "memory.current"), "50\n")
|
|
writeSamplerFixture(t, filepath.Join(root, "memory.max"), "100\n")
|
|
writeSamplerFixture(t, filepath.Join(root, "cpu.max"), "100000 100000\n")
|
|
writeSamplerFixture(t, filepath.Join(root, "cpu.stat"), "usage_usec 100000\nnr_throttled 1\n")
|
|
sampler := NewSystemSamplerAt(root)
|
|
first := sampler.Sample(2, 10)
|
|
if first.MemoryCurrentBytes != 50 || first.MemoryLimitBytes != 100 || first.DBConnections != 2 {
|
|
t.Fatalf("first sample=%+v", first)
|
|
}
|
|
time.Sleep(10 * time.Millisecond)
|
|
writeSamplerFixture(t, filepath.Join(root, "cpu.stat"), "usage_usec 105000\nnr_throttled 2\n")
|
|
second := sampler.Sample(3, 10)
|
|
if second.CPUUtilization <= 0 || !second.CPUThrottled {
|
|
t.Fatalf("second sample=%+v", second)
|
|
}
|
|
}
|
|
|
|
func writeSamplerFixture(t *testing.T, path, value string) {
|
|
t.Helper()
|
|
if err := os.WriteFile(path, []byte(value), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|