logging: add a Close function to the Tracer (#4298)

* logging: add a Close function to the Tracer

* close the Tracer when the Transport is closed
This commit is contained in:
Marten Seemann 2024-02-03 12:12:15 +07:00 committed by GitHub
parent b675e34254
commit 07ec3245bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 65 additions and 1 deletions

View file

@ -41,6 +41,42 @@ func (m *MockTracer) EXPECT() *MockTracerMockRecorder {
return m.recorder
}
// Close mocks base method.
func (m *MockTracer) Close() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Close")
}
// Close indicates an expected call of Close.
func (mr *MockTracerMockRecorder) Close() *TracerCloseCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockTracer)(nil).Close))
return &TracerCloseCall{Call: call}
}
// TracerCloseCall wrap *gomock.Call
type TracerCloseCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *TracerCloseCall) Return() *TracerCloseCall {
c.Call = c.Call.Return()
return c
}
// Do rewrite *gomock.Call.Do
func (c *TracerCloseCall) Do(f func()) *TracerCloseCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *TracerCloseCall) DoAndReturn(f func()) *TracerCloseCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// Debug mocks base method.
func (m *MockTracer) Debug(arg0, arg1 string) {
m.ctrl.T.Helper()

View file

@ -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"

View file

@ -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
}