test(channelbridge): 窗口夹具按截止时刻推钟 + 去掉无法证实的替身锁(M33 r1 复审)
P1-1(channelbridge 的 -race 门仍红,红在用例不确定性而不是竞态): - coalesceTimers 改成**截止时刻**语义:每次 after(d) 记 at = 注入时钟 + d, 推钟只把时钟推进到「当前最早的截止时刻」再触发它。旧写法按 FIFO 逐个触发并 按请求时长累加,实测 12 条消息内攒到 5 个废弃定时器把时钟推 +10s(窗口 2s、 绝对上限 6s)⇒ 循环头走「到点直接发车、不 takeAll」的分支,队列尾部落到下一批。 - 推钟前强制「车道排空」这条不变量(pump/advanceAndFire/waitIdle): 时钟只表示时间过去,它一转就可能跳过 takeAll,因此先等 worker 把货收进本批。 - sendSettled:投递后按**序号**等「这次投递之后新挂的定时器」(旧的都已被 worker 放弃、再没人监听),供「投递与推钟交替」的用例(每 500ms 一条的绝对上限用例)。 - fireLatest/advanceAndFire 带 done 谓词重试,避免「登记与触发之间续臂」导致 推了钟却没人醒;waitIdle 一边等一边推窗口(worker 停在窗口里时永远走不到退休)。 - 用例侧只补相位与等待,不动断言:TwelveBurst 读历史前等 assistant 行落库; 准入用例断言「最新一次续臂」(原来按下标取 d[1],隐含臂数假设); stale 用例两条都投完再推时钟(车道不会在两条之间退休)。 P2-1(替身锁无法用变异证实)选 A:删掉 stubChatter/stubSessions 的锁与访问器, 退回原字段访问,并写清理由 —— 21 个用例全走同步便捷路径 (b.process → processFrom → runBatch → Loop.Run),DEV HEAD 上 -race 数十次跑 (含把锁删掉的变异)DATA RACE 恒为 0;若将来从车道 worker 触碰这些字段必须加锁 并补 -race 用例。 证据:go test -race -count=3 ./internal/services/channelbridge/ 连跑 6 轮 18/18 全绿、DATA RACE=0;coalesce 子集 -count=80 全绿;整包 -race -count=20 全绿; 全树 go build/vet/test -count=1 全绿。
This commit is contained in:
1 parent
7d9b2132bb
commit
1ae9158250
20 files changed
+584
-371
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.clearSessionID()
|
||||
chat.sessionID = ""
|
||||
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.clearSessionID()
|
||||
chat.sessionID = ""
|
||||
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