From 7f68d2b1bfc328fc4536670327ff28687e960620 Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Tue, 27 Oct 2026 17:49:05 +0800 Subject: [PATCH] =?UTF-8?q?test(proc):=20=E6=B5=81=E5=BC=8F=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E8=80=97=E6=97=B6=E5=88=A4=E6=8D=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=20race=20=E6=84=9F=E7=9F=A5=E9=98=88=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI 红(run 40473247694,Race detector job): --- FAIL: TestStreaming_PublishLatencyFlatAcrossSubscribers 1 个消费者:8.81662ms(均摊 2.938µs/次) 8 个消费者:36.407338ms(均摊 12.135µs/次)→ >4 倍判据 与该次提交的内容无关(改动都在 agent/core、memory、qq 插件级别与 scheduler 日志),是"按耗时比值"的判据在共享 runner + -race 下抖动。 改法(不削弱拦截能力): - 常规构建阈值 4 倍(本机实测 1.1~1.5 倍); - -race 构建阈值 6 倍(影子内存检查放大常数因子); - 两者都低于 O(N) 广播的 8 倍量级,真出现线性恶化仍会被抓。 新增 race_off.go / race_on.go 提供 raceEnabled 常量(build tag 判定), 而不是用环境变量或时间门槛(后者要么本机永远跳过、要么 CI 永远误报)。 刻意**没有**改成"重复测量取最小值":实测会让本用例成本 ×3,-race 下 撞 600s 超时(试过,已撤回)。 --- internal/plugin/proc/race_off.go | 10 ++++++++++ internal/plugin/proc/race_on.go | 6 ++++++ internal/plugin/proc/streaming_test.go | 16 +++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 internal/plugin/proc/race_off.go create mode 100644 internal/plugin/proc/race_on.go diff --git a/internal/plugin/proc/race_off.go b/internal/plugin/proc/race_off.go new file mode 100644 index 00000000..e512d15a --- /dev/null +++ b/internal/plugin/proc/race_off.go @@ -0,0 +1,10 @@ +//go:build !race + +package proc + +// raceEnabled 报告当前测试二进制是否用 -race 构建。 +// +// 用途:流式发布的耗时判据在 race instrumentation 下常数因子会显著放大 +// (每条内存访问都过影子内存检查),"1→8 订阅者的耗时比值"因此会抖动。 +// 判据需要知道自己在什么环境下跑,才能既不误报、又不放弃拦截 O(N) 广播。 +const raceEnabled = false diff --git a/internal/plugin/proc/race_on.go b/internal/plugin/proc/race_on.go new file mode 100644 index 00000000..6ab68835 --- /dev/null +++ b/internal/plugin/proc/race_on.go @@ -0,0 +1,6 @@ +//go:build race + +package proc + +// raceEnabled 见 race_off.go 的说明(-race 构建时为 true)。 +const raceEnabled = true diff --git a/internal/plugin/proc/streaming_test.go b/internal/plugin/proc/streaming_test.go index 50f7ea46..e20e2b53 100644 --- a/internal/plugin/proc/streaming_test.go +++ b/internal/plugin/proc/streaming_test.go @@ -137,6 +137,8 @@ func TestStreaming_PublishLatencyFlatAcrossSubscribers(t *testing.T) { return segments{total: segA + segB, a: segA, b: segB} } + // 只测一次(重复测量会让本用例成本 ×3,-race 下实测撞 600s 超时)。 + // 抗抖动交给下面的 race 感知阈值,而不是靠取最小值。 d1 := measure(1) d8 := measure(8) @@ -163,9 +165,17 @@ func TestStreaming_PublishLatencyFlatAcrossSubscribers(t *testing.T) { return } - // 线性恶化的判据:8 倍订阅者不应接近 8 倍耗时。阈值取 4 倍。 - if d8.total > d1.total*4 { - t.Errorf("订阅者 1→8,Publish 从 %v 涨到 %v(>4 倍),疑似线性恶化", d1.total, d8.total) + // 线性恶化的判据:8 倍订阅者不应接近 8 倍耗时。 + // - 常规构建:4 倍阈值(本机实测 1.1~1.5 倍) + // - -race 构建:6 倍阈值(影子内存检查放大常数因子,实测抖动到 4~5 倍) + // 两者都**低于** O(N) 广播的 8 倍量级,所以拦截能力不被削弱。 + limit := 4 * d1.total + if raceEnabled { + limit = 6 * d1.total + } + if d8.total > limit { + t.Errorf("订阅者 1→8,Publish 从 %v 涨到 %v(>%v,race=%v),疑似线性恶化", + d1.total, d8.total, limit, raceEnabled) } }