0826e17063
- 为控制消息增加优先级、公平调度、队列字节预算和自适应批处理 - 支持可取消的写门等待,收紧 shared/dedicated bulk、stream 和 Reply 写入边界 - 修复 bulk reset/close、连接 handoff 和安全 profile 切换时序 - 保留旧取消与超时错误契约,新增阶段化 TransportSendError - 增加 ReplyCtx、ReplyObjCtx、写超时配置及黑洞连接和竞态回归测试
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package notify
|
|
|
|
import (
|
|
"b612.me/stario"
|
|
"context"
|
|
"fmt"
|
|
"math"
|
|
"net"
|
|
"sync/atomic"
|
|
"testing"
|
|
)
|
|
|
|
var testAcceptedPeerSeq atomic.Uint64
|
|
|
|
func newRunningPeerAttachServerForTest(t *testing.T, configure func(*ServerCommon)) *ServerCommon {
|
|
t.Helper()
|
|
server := NewServer().(*ServerCommon)
|
|
if configure != nil {
|
|
configure(server)
|
|
}
|
|
stopCtx, stopFn := context.WithCancel(context.Background())
|
|
queue := stario.NewQueueCtx(stopCtx, 8, math.MaxUint32)
|
|
inboundDispatcher := newInboundDispatcher()
|
|
server.setServerSessionRuntime(&serverSessionRuntime{
|
|
stopCtx: stopCtx,
|
|
stopFn: stopFn,
|
|
queue: queue,
|
|
inboundDispatcher: inboundDispatcher,
|
|
})
|
|
server.markSessionStarted()
|
|
|
|
transportCtx, transportStop := context.WithCancel(context.Background())
|
|
go server.loadMessageLoop(nil, transportCtx, queue, nil, nil)
|
|
|
|
t.Cleanup(func() {
|
|
transportStop()
|
|
stopFn()
|
|
inboundDispatcher.CloseAndWait()
|
|
})
|
|
return server
|
|
}
|
|
|
|
func bootstrapPeerAttachLogicalForTest(t *testing.T, server *ServerCommon, conn net.Conn) *LogicalConn {
|
|
t.Helper()
|
|
if server == nil {
|
|
t.Fatal("server is nil")
|
|
}
|
|
id := fmt.Sprintf("accepted-%d", testAcceptedPeerSeq.Add(1))
|
|
logical := server.bootstrapAcceptedLogical(id, conn.RemoteAddr(), conn)
|
|
if logical == nil {
|
|
t.Fatal("bootstrapAcceptedLogical returned nil")
|
|
}
|
|
return logical
|
|
}
|
|
|
|
func bootstrapPeerAttachConnForTest(t *testing.T, server *ServerCommon, conn net.Conn) *ClientConn {
|
|
return clientConnFromLogical(bootstrapPeerAttachLogicalForTest(t, server, conn))
|
|
}
|