remove Tracer from Config, put ConnectionTracer constructor there

This commit is contained in:
Marten Seemann 2023-04-28 12:49:11 +02:00
parent 5544f0f9a1
commit 07ad2cbee2
31 changed files with 202 additions and 331 deletions

View file

@ -1,7 +1,6 @@
package logging
import (
"context"
"errors"
"net"
"time"
@ -37,46 +36,6 @@ var _ = Describe("Tracing", func() {
tracer = NewMultiplexedTracer(tr1, tr2)
})
It("multiplexes the TracerForConnection call", func() {
ctx := context.Background()
connID := protocol.ParseConnectionID([]byte{1, 2, 3})
tr1.EXPECT().TracerForConnection(ctx, PerspectiveClient, connID)
tr2.EXPECT().TracerForConnection(ctx, PerspectiveClient, connID)
tracer.TracerForConnection(ctx, PerspectiveClient, connID)
})
It("uses multiple connection tracers", func() {
ctx := context.Background()
ctr1 := NewMockConnectionTracer(mockCtrl)
ctr2 := NewMockConnectionTracer(mockCtrl)
connID := protocol.ParseConnectionID([]byte{1, 2, 3})
tr1.EXPECT().TracerForConnection(ctx, PerspectiveServer, connID).Return(ctr1)
tr2.EXPECT().TracerForConnection(ctx, PerspectiveServer, connID).Return(ctr2)
tr := tracer.TracerForConnection(ctx, PerspectiveServer, connID)
ctr1.EXPECT().LossTimerCanceled()
ctr2.EXPECT().LossTimerCanceled()
tr.LossTimerCanceled()
})
It("handles tracers that return a nil ConnectionTracer", func() {
ctx := context.Background()
ctr1 := NewMockConnectionTracer(mockCtrl)
connID := protocol.ParseConnectionID([]byte{1, 2, 3, 4})
tr1.EXPECT().TracerForConnection(ctx, PerspectiveServer, connID).Return(ctr1)
tr2.EXPECT().TracerForConnection(ctx, PerspectiveServer, connID)
tr := tracer.TracerForConnection(ctx, PerspectiveServer, connID)
ctr1.EXPECT().LossTimerCanceled()
tr.LossTimerCanceled()
})
It("returns nil when all tracers return a nil ConnectionTracer", func() {
ctx := context.Background()
connID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5})
tr1.EXPECT().TracerForConnection(ctx, PerspectiveClient, connID)
tr2.EXPECT().TracerForConnection(ctx, PerspectiveClient, connID)
Expect(tracer.TracerForConnection(ctx, PerspectiveClient, connID)).To(BeNil())
})
It("traces the PacketSent event", func() {
remote := &net.UDPAddr{IP: net.IPv4(4, 3, 2, 1)}
hdr := &Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})}