From cba33d2a6f8d06791b0b91f9708ec0e1a625f8ab Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Sun, 13 Sep 2026 10:25:49 +0800 Subject: [PATCH] =?UTF-8?q?test(resident):=20=E5=8E=8B=E5=8A=9B=E8=A7=84?= =?UTF-8?q?=E6=A8=A1=E5=8F=AF=E7=94=A8=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E6=94=BE=E5=A4=A7=EF=BC=88RESIDENT=5FSTRESS=5FN=20/=20RESIDENT?= =?UTF-8?q?=5FSTRESS=5FROUNDS=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 默认仍是 8 子 × 12 轮(CI 友好);要跑加重压力就放大: RESIDENT_STRESS_N=64 RESIDENT_STRESS_ROUNDS=40 go test -race -count=2 ./internal/agent/core/ -run TestResident_E2EAndStress 实测已跑: - 24 子 × 25 轮(-race):通过 - 64 子 × 40 轮(-race -count=2,即 5120 轮次):通过 --- internal/agent/core/resident_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/agent/core/resident_test.go b/internal/agent/core/resident_test.go index 1213123..ad6c505 100644 --- a/internal/agent/core/resident_test.go +++ b/internal/agent/core/resident_test.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" "strings" "testing" "time" @@ -301,14 +302,25 @@ func TestResident_ContextFullAndDispositions(t *testing.T) { } } +func envInt(key string, def int) int { + if v := os.Getenv(key); v != "" { + if n, err := strconv.Atoi(v); err == nil && n > 0 { + return n + } + } + return def +} + // ---- N7:端到端 + 压力 ---- func TestResident_E2EAndStress(t *testing.T) { parent, _, dir := newRootForResidents(t) reg := parent.io.ChannelRegistry() - const nResidents = 8 - const roundsEach = 12 + // 压力规模可用环境变量放大(默认 8 子 × 12 轮): + // RESIDENT_STRESS_N / RESIDENT_STRESS_ROUNDS + nResidents := envInt("RESIDENT_STRESS_N", 8) + roundsEach := envInt("RESIDENT_STRESS_ROUNDS", 12) ids := make([]string, 0, nResidents) for i := 0; i < nResidents; i++ { id := "sub-" + string(rune('a'+i))