test(testhealth): 替身竞态加锁 + 墙钟断言硬度(M33)
四处测试健康债务,只改 *_test.go,不动生产代码、不降并发: - channelbridge:stubChatter / stubSessions 的跨 goroutine 字段一律经 mu 访问 (Run/GetOrCreate 在车道 worker 上写、测试 goroutine 读,两者无 happens-before; 负向断言「等一会儿再看循环有没有被驱动」尤其如此)。读写走访问器,Messages() 返回副本;t.Parallel 与并发度不变。 - plugins/tools/io:claimProbeTimeout 2s(真实时间预算)→ 60s,并由 claimProbeWait 按 t.Deadline 收缩。探针只等 goroutine 被调度(无时间语义),放大余量把 「机器快慢」从断言里去掉,死锁仍以断言失败暴露。 - backthink:TestSelfWakeGate_WindowExpiry 窗口 120ms → 6s(给 waitFor 的 4s 上界 留 2s 余量),到期等待改为按首次受理时刻推算 window+250ms,不再盲睡 3×窗口。 另修 TestSelfWakeStatus_MatchesReceiptAndTracksPendingSlot:worker 先 take 再进 Think,卡 Think 并不占待跑槽 —— 改为「上一轮把 worker 占住再断言 Pending」。 - memory:墙钟实测用例显式给闸 5s 预算(measureGateBudget),不再因默认 150ms 超时 fail-open 打炸「每轮都真扫真判」前置断言;并把 GateFailed 纳入该断言。
This commit is contained in:
1 parent
da6a365222
commit
7d9b2132bb
18 files changed
+407
-242
No files matched your search
@@ -82,13 +82,13 @@ func TestStrangerPrivateChatRespondsIncludingQuietHours(t *testing.T) {
|
||||
|
||||
msg := strangerDirectMsg("777", "在吗,普通的一句话")
|
||||
actor := session.ResolveActor(msg, b.owner)
|
||||
if ok, reason := b.shouldRespond(context.Background(), msg, actor, sess.sess, ad); !ok {
|
||||
if ok, reason := b.shouldRespond(context.Background(), msg, actor, sess.Sess(), ad); !ok {
|
||||
t.Fatalf("shouldRespond = false (%s), want true(陌生人私聊一律正常聊天)", reason)
|
||||
}
|
||||
|
||||
b.process(context.Background(), msg)
|
||||
if chat.sessionID != "sess-s" {
|
||||
t.Fatalf("loop session = %q, want the isolated sess-s", chat.sessionID)
|
||||
if chat.SessionID() != "sess-s" {
|
||||
t.Fatalf("loop session = %q, want the isolated sess-s", chat.SessionID())
|
||||
}
|
||||
if len(ad.sends) != 1 || ad.sends[0].Content != "你好呀" {
|
||||
t.Fatalf("stranger replies = %+v, want one text reply", ad.sends)
|
||||
@@ -111,19 +111,19 @@ func TestStrangerPrivateFlowControlPerSender(t *testing.T) {
|
||||
b, sess, ad := newStrangerBridge(t, chat, hist, at, log)
|
||||
|
||||
for i := 0; i < adapter.FlowDirectDefault; i++ {
|
||||
chat.sessionID = ""
|
||||
chat.clearSessionID()
|
||||
b.process(context.Background(), strangerDirectMsg("777", "第 "+itoa(i)+" 句"))
|
||||
if chat.sessionID != "sess-s" {
|
||||
t.Fatalf("额度内第 %d 条被拒(session=%q)", i+1, chat.sessionID)
|
||||
if chat.SessionID() != "sess-s" {
|
||||
t.Fatalf("额度内第 %d 条被拒(session=%q)", i+1, chat.SessionID())
|
||||
}
|
||||
}
|
||||
|
||||
// 第 N+1 条超限:不回,只登记,且有可见日志。
|
||||
before := len(hist.records())
|
||||
chat.sessionID = ""
|
||||
chat.clearSessionID()
|
||||
b.process(context.Background(), strangerDirectMsg("777", "刷屏第 N+1 句"))
|
||||
if chat.sessionID != "" {
|
||||
t.Fatalf("超限消息驱动了循环:session=%q", chat.sessionID)
|
||||
if chat.SessionID() != "" {
|
||||
t.Fatalf("超限消息驱动了循环:session=%q", chat.SessionID())
|
||||
}
|
||||
if got := len(hist.records()) - before; got != 1 {
|
||||
t.Fatalf("超限消息新增登记 %d 条,want 1(只登记不回)", got)
|
||||
@@ -136,7 +136,7 @@ func TestStrangerPrivateFlowControlPerSender(t *testing.T) {
|
||||
|
||||
// 另一条发送者:额度独立,第一条照常回答。
|
||||
other := strangerDirectMsg("888", "我是另一个人")
|
||||
if ok, reason := b.shouldRespond(context.Background(), other, session.ResolveActor(other, b.owner), sess.sess, ad); !ok {
|
||||
if ok, reason := b.shouldRespond(context.Background(), other, session.ResolveActor(other, b.owner), sess.Sess(), ad); !ok {
|
||||
t.Fatalf("另一个发送者被同一额度挤占:reason=%s", reason)
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func TestStrangerPrivateSecondTurnAnsweredNotThrottled(t *testing.T) {
|
||||
t.Cleanup(func() { gate.ReleaseTurn(msg) })
|
||||
|
||||
b.process(context.Background(), msg)
|
||||
if chat.sessionID == "" {
|
||||
if chat.SessionID() == "" {
|
||||
t.Fatal("回合槽被占时消息没有回答:M23 的口径是排队回答,不是不回")
|
||||
}
|
||||
if got := len(hist.records()); got != 2 {
|
||||
@@ -201,8 +201,8 @@ func TestNonOwnerLowValueSystemEventRegisteredOnly(t *testing.T) {
|
||||
msg.Sender.Role = adapter.RoleSystem
|
||||
b.process(context.Background(), msg)
|
||||
|
||||
if chat.sessionID != "" || len(chat.messages) != 0 {
|
||||
t.Fatalf("低价值系统事件驱动了循环:session=%q messages=%+v", chat.sessionID, chat.messages)
|
||||
if chat.SessionID() != "" || len(chat.Messages()) != 0 {
|
||||
t.Fatalf("低价值系统事件驱动了循环:session=%q messages=%+v", chat.SessionID(), chat.Messages())
|
||||
}
|
||||
if got := len(hist.records()); got != 1 {
|
||||
t.Fatalf("records = %d, want 1(只登记,不回复)", got)
|
||||
|
||||
Reference in new issue
Block a user