Persist QUIC fabric closed evictions

This commit is contained in:
2026-05-16 12:48:32 +03:00
parent 28c26a5103
commit 49bc003193
3 changed files with 49 additions and 0 deletions
@@ -354,6 +354,7 @@ func (t *QUICFabricTransport) Snapshot() QUICFabricTransportSnapshot {
select {
case <-entry.conn.Context().Done():
delete(t.conns, key)
t.stats.ClosedEvicted++
snapshot.Stats.ClosedEvicted++
default:
snapshot.ActiveCount++
@@ -235,6 +235,51 @@ func TestQUICFabricTransportPrunesIdleConnections(t *testing.T) {
}
}
func TestQUICFabricTransportSnapshotPersistsClosedEvictions(t *testing.T) {
server, err := StartQUICFabricServer(context.Background(), QUICFabricServerConfig{
ListenAddr: "127.0.0.1:0",
TLSConfig: testQUICTLSConfig(t),
})
if err != nil {
t.Fatalf("start quic fabric server: %v", err)
}
defer server.Close()
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
transport := NewQUICFabricTransport(nil)
defer transport.Close()
target := FabricTransportTarget{
PeerID: "node-b",
Endpoint: server.Addr().String(),
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
NextProtos: []string{fabricQUICNextProto},
},
Timeout: time.Second,
}
session, err := transport.Connect(ctx, target)
if err != nil {
t.Fatalf("connect: %v", err)
}
defer session.Close()
key := quicFabricConnKey(target)
transport.mu.Lock()
entry := transport.conns[key]
transport.mu.Unlock()
if entry == nil || entry.conn == nil {
t.Fatalf("cached connection missing")
}
_ = entry.conn.CloseWithError(0, "test closed")
<-entry.conn.Context().Done()
first := transport.Snapshot()
second := transport.Snapshot()
if first.Stats.ClosedEvicted != 1 || second.Stats.ClosedEvicted != 1 {
t.Fatalf("closed eviction stats were not persisted: first=%+v second=%+v", first, second)
}
}
func TestQUICFabricTransportLimitsStreamsPerConnection(t *testing.T) {
server, err := StartQUICFabricServer(context.Background(), QUICFabricServerConfig{
ListenAddr: "127.0.0.1:0",