New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transport: add peer information to http2Server and http2Client context #5589
Changes from 4 commits
dde7635
4a55ac5
33e6de3
a2e0810
23e151d
0949681
661205c
1e0e6d0
1bb5d72
ee6c28a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"google.golang.org/grpc/peer" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"golang.org/x/net/http2" | ||
"golang.org/x/net/http2/hpack" | ||
|
@@ -2450,3 +2452,20 @@ func TestConnectionError_Unwrap(t *testing.T) { | |
t.Error("ConnectionError does not unwrap") | ||
} | ||
} | ||
|
||
// Verify Peer is set in server context. | ||
func TestPeerSetInServerContext(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please specify our test struct as the receiver for this test. This will ensure that our leakcheck runs at the end of the test. func (s) TestPeerSetInServerContext(t *testing.T) { ... } |
||
server := setUpServerOnly(t, 0, &ServerConfig{}, suspended) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You either need to use |
||
defer server.stop() | ||
|
||
for k := range server.conns { | ||
sc, ok := k.(*http2Server) | ||
if !ok { | ||
t.Fatalf("Failed to convert %v to *http2Server", k) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to include the actual type as well: t.Fatalf("ServerTransport is of type %T, want %T, k, &http2Server{}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome! |
||
} | ||
_, ok = peer.FromContext(sc.ctx) | ||
if !ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines can be combined into one. |
||
t.Fatalf("peer expected in server context, but actually not found.") | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably be simplified as: