MCPcopy
hub / github.com/grpc/grpc-go / TestClientHandshakeInfoDialer

Method TestClientHandshakeInfoDialer

internal/transport/transport_test.go:2737–2774  ·  view source on GitHub ↗

TestClientHandshakeInfoDialer adds attributes to the resolver.Address passes to NewHTTP2Client and verifies that these attributes are received by a custom dialer.

(t *testing.T)

Source from the content-addressed store, hash-verified

2735// NewHTTP2Client and verifies that these attributes are received by a custom
2736// dialer.
2737func (s) TestClientHandshakeInfoDialer(t *testing.T) {
2738 server := setUpServerOnly(t, 0, &ServerConfig{BufferPool: mem.DefaultBufferPool()}, pingpong)
2739 defer server.stop()
2740
2741 const (
2742 testAttrKey = "foo"
2743 testAttrVal = "bar"
2744 )
2745 addr := resolver.Address{
2746 Addr: "localhost:" + server.port,
2747 Attributes: attributes.New(testAttrKey, testAttrVal),
2748 }
2749 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
2750 defer cancel()
2751
2752 var attr *attributes.Attributes
2753 dialer := func(ctx context.Context, addr string) (net.Conn, error) {
2754 ai := credentials.ClientHandshakeInfoFromContext(ctx)
2755 attr = ai.Attributes
2756 return (&net.Dialer{}).DialContext(ctx, "tcp", addr)
2757 }
2758
2759 copts := ConnectOptions{
2760 Dialer: dialer,
2761 ChannelzParent: channelzSubChannel(t),
2762 BufferPool: mem.DefaultBufferPool(),
2763 }
2764 tr, err := NewHTTP2Client(ctx, ctx, addr, copts, func(GoAwayInfo) {})
2765 if err != nil {
2766 t.Fatalf("NewHTTP2Client(): %v", err)
2767 }
2768 defer tr.Close(fmt.Errorf("closed manually by test"))
2769
2770 wantAttr := attributes.New(testAttrKey, testAttrVal)
2771 if gotAttr := attr; !cmp.Equal(gotAttr, wantAttr, cmp.AllowUnexported(attributes.Attributes{})) {
2772 t.Errorf("Received attributes %v in custom dialer, want %v", gotAttr, wantAttr)
2773 }
2774}
2775
2776func newTestClientStream() *ClientStream {
2777 return &ClientStream{

Callers

nothing calls this directly

Calls 12

DefaultBufferPoolFunction · 0.92
NewFunction · 0.92
setUpServerOnlyFunction · 0.85
channelzSubChannelFunction · 0.85
NewHTTP2ClientFunction · 0.85
stopMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
EqualMethod · 0.65
DialContextMethod · 0.45

Tested by

no test coverage detected