Skip to content

Commit

Permalink
expose quic-go's connection tracing ID on the Session.Context (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Oct 24, 2022
1 parent fe81d8b commit c3772f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ type Session struct {
}

func newSession(sessionID sessionID, qconn http3.StreamCreator, requestStr quic.Stream) *Session {
ctx, ctxCancel := context.WithCancel(context.Background())
tracingID := qconn.Context().Value(quic.ConnectionTracingKey).(uint64)
ctx, ctxCancel := context.WithCancel(context.WithValue(context.Background(), quic.ConnectionTracingKey, tracingID))
c := &Session{
sessionID: sessionID,
qconn: qconn,
Expand Down
7 changes: 6 additions & 1 deletion session_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package webtransport

import (
"context"
"io"
"testing"

Expand Down Expand Up @@ -40,6 +41,7 @@ func TestCloseStreamsOnClose(t *testing.T) {
defer ctrl.Finish()

mockSess := NewMockStreamCreator(ctrl)
mockSess.EXPECT().Context().Return(context.WithValue(context.Background(), quic.ConnectionTracingKey, uint64(1337)))
sess := newSession(42, mockSess, newMockRequestStream(ctrl))

str := NewMockStream(ctrl)
Expand All @@ -63,7 +65,10 @@ func TestAddStreamAfterSessionClose(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

sess := newSession(42, NewMockStreamCreator(ctrl), newMockRequestStream(ctrl))
mockSess := NewMockStreamCreator(ctrl)
mockSess.EXPECT().Context().Return(context.WithValue(context.Background(), quic.ConnectionTracingKey, uint64(1337)))

sess := newSession(42, mockSess, newMockRequestStream(ctrl))
require.NoError(t, sess.Close())

str := NewMockStream(ctrl)
Expand Down

0 comments on commit c3772f6

Please sign in to comment.