Skip to content

Commit

Permalink
logging: add a Close function to the Tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Feb 2, 2024
1 parent fc634a6 commit e23e1d2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
36 changes: 36 additions & 0 deletions internal/mocks/logging/internal/tracer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/mocks/logging/mockgen.go
Expand Up @@ -15,6 +15,7 @@ type Tracer interface {
SentVersionNegotiationPacket(_ net.Addr, dest, src logging.ArbitraryLenConnectionID, _ []logging.VersionNumber)
DroppedPacket(net.Addr, logging.PacketType, logging.ByteCount, logging.PacketDropReason)
Debug(name, msg string)
Close()
}

//go:generate sh -c "go run go.uber.org/mock/mockgen -typed -build_flags=\"-tags=gomock\" -package internal -destination internal/connection_tracer.go github.com/quic-go/quic-go/internal/mocks/logging ConnectionTracer"
Expand Down
3 changes: 3 additions & 0 deletions internal/mocks/logging/tracer.go
Expand Up @@ -28,5 +28,8 @@ func NewMockTracer(ctrl *gomock.Controller) (*logging.Tracer, *MockTracer) {
Debug: func(name, msg string) {
t.Debug(name, msg)
},
Close: func() {
t.Close()
},
}, t
}
6 changes: 6 additions & 0 deletions logging/multiplex_test.go
Expand Up @@ -70,6 +70,12 @@ var _ = Describe("Tracing", func() {
tr2.EXPECT().Debug("foo", "bar")
tracer.Debug("foo", "bar")
})

It("traces the Close event", func() {
tr1.EXPECT().Close()
tr2.EXPECT().Close()
tracer.Close()
})
})
})

Expand Down
8 changes: 8 additions & 0 deletions logging/tracer.go
Expand Up @@ -8,6 +8,7 @@ type Tracer struct {
SentVersionNegotiationPacket func(_ net.Addr, dest, src ArbitraryLenConnectionID, _ []VersionNumber)
DroppedPacket func(net.Addr, PacketType, ByteCount, PacketDropReason)
Debug func(name, msg string)
Close func()
}

// NewMultiplexedTracer creates a new tracer that multiplexes events to multiple tracers.
Expand Down Expand Up @@ -47,5 +48,12 @@ func NewMultiplexedTracer(tracers ...*Tracer) *Tracer {
}
}
},
Close: func() {
for _, t := range tracers {
if t.Close != nil {
t.Close()
}
}
},
}
}

0 comments on commit e23e1d2

Please sign in to comment.