@@ -40,6 +40,7 @@ import (
4040 "google.golang.org/grpc/attributes"
4141 "google.golang.org/grpc/codes"
4242 "google.golang.org/grpc/credentials"
43+ "google.golang.org/grpc/internal/channelz"
4344 "google.golang.org/grpc/internal/grpctest"
4445 "google.golang.org/grpc/internal/leakcheck"
4546 "google.golang.org/grpc/internal/testutils"
@@ -55,16 +56,6 @@ func Test(t *testing.T) {
5556 grpctest .RunSubTests (t , s {})
5657}
5758
58- type server struct {
59- lis net.Listener
60- port string
61- startedErr chan error // error (or nil) with server start value
62- mu sync.Mutex
63- conns map [ServerTransport ]bool
64- h * testStreamHandler
65- ready chan struct {}
66- }
67-
6859var (
6960 expectedRequest = []byte ("ping" )
7061 expectedResponse = []byte ("pong" )
@@ -298,6 +289,25 @@ func (h *testStreamHandler) handleStreamDelayRead(t *testing.T, s *Stream) {
298289 }
299290}
300291
292+ type server struct {
293+ lis net.Listener
294+ port string
295+ startedErr chan error // error (or nil) with server start value
296+ mu sync.Mutex
297+ conns map [ServerTransport ]bool
298+ h * testStreamHandler
299+ ready chan struct {}
300+ channelzID * channelz.Identifier
301+ }
302+
303+ func newTestServer () * server {
304+ return & server {
305+ startedErr : make (chan error , 1 ),
306+ ready : make (chan struct {}),
307+ channelzID : channelz .NewIdentifierForTesting (channelz .RefServer , time .Now ().Unix (), nil ),
308+ }
309+ }
310+
301311// start starts server. Other goroutines should block on s.readyChan for further operations.
302312func (s * server ) start (t * testing.T , port int , serverConfig * ServerConfig , ht hType ) {
303313 var err error
@@ -421,9 +431,10 @@ func (s *server) addr() string {
421431 return s .lis .Addr ().String ()
422432}
423433
424- func setUpServerOnly (t * testing.T , port int , serverConfig * ServerConfig , ht hType ) * server {
425- server := & server {startedErr : make (chan error , 1 ), ready : make (chan struct {})}
426- go server .start (t , port , serverConfig , ht )
434+ func setUpServerOnly (t * testing.T , port int , sc * ServerConfig , ht hType ) * server {
435+ server := newTestServer ()
436+ sc .ChannelzParentID = server .channelzID
437+ go server .start (t , port , sc , ht )
427438 server .wait (t , 2 * time .Second )
428439 return server
429440}
@@ -432,9 +443,11 @@ func setUp(t *testing.T, port int, maxStreams uint32, ht hType) (*server, *http2
432443 return setUpWithOptions (t , port , & ServerConfig {MaxStreams : maxStreams }, ht , ConnectOptions {})
433444}
434445
435- func setUpWithOptions (t * testing.T , port int , serverConfig * ServerConfig , ht hType , copts ConnectOptions ) (* server , * http2Client , func ()) {
436- server := setUpServerOnly (t , port , serverConfig , ht )
446+ func setUpWithOptions (t * testing.T , port int , sc * ServerConfig , ht hType , copts ConnectOptions ) (* server , * http2Client , func ()) {
447+ server := setUpServerOnly (t , port , sc , ht )
437448 addr := resolver.Address {Addr : "localhost:" + server .port }
449+ copts .ChannelzParentID = channelz .NewIdentifierForTesting (channelz .RefSubChannel , time .Now ().Unix (), nil )
450+
438451 connectCtx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (2 * time .Second ))
439452 ct , connErr := NewClientTransport (connectCtx , context .Background (), addr , copts , func () {}, func (GoAwayReason ) {}, func () {})
440453 if connErr != nil {
@@ -1298,11 +1311,14 @@ func (s) TestClientWithMisbehavedServer(t *testing.T) {
12981311 }()
12991312 connectCtx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (2 * time .Second ))
13001313 defer cancel ()
1301- ct , err := NewClientTransport (connectCtx , context .Background (), resolver.Address {Addr : lis .Addr ().String ()}, ConnectOptions {}, func () {}, func (GoAwayReason ) {}, func () {})
1314+
1315+ copts := ConnectOptions {ChannelzParentID : channelz .NewIdentifierForTesting (channelz .RefSubChannel , time .Now ().Unix (), nil )}
1316+ ct , err := NewClientTransport (connectCtx , context .Background (), resolver.Address {Addr : lis .Addr ().String ()}, copts , func () {}, func (GoAwayReason ) {}, func () {})
13021317 if err != nil {
13031318 t .Fatalf ("Error while creating client transport: %v" , err )
13041319 }
13051320 defer ct .Close (fmt .Errorf ("closed manually by test" ))
1321+
13061322 str , err := ct .NewStream (connectCtx , & CallHdr {})
13071323 if err != nil {
13081324 t .Fatalf ("Error while creating stream: %v" , err )
@@ -2180,7 +2196,11 @@ func (s) TestClientHandshakeInfo(t *testing.T) {
21802196 defer cancel ()
21812197 creds := & attrTransportCreds {}
21822198
2183- tr , err := NewClientTransport (ctx , context .Background (), addr , ConnectOptions {TransportCredentials : creds }, func () {}, func (GoAwayReason ) {}, func () {})
2199+ copts := ConnectOptions {
2200+ TransportCredentials : creds ,
2201+ ChannelzParentID : channelz .NewIdentifierForTesting (channelz .RefSubChannel , time .Now ().Unix (), nil ),
2202+ }
2203+ tr , err := NewClientTransport (ctx , context .Background (), addr , copts , func () {}, func (GoAwayReason ) {}, func () {})
21842204 if err != nil {
21852205 t .Fatalf ("NewClientTransport(): %v" , err )
21862206 }
@@ -2217,7 +2237,11 @@ func (s) TestClientHandshakeInfoDialer(t *testing.T) {
22172237 return (& net.Dialer {}).DialContext (ctx , "tcp" , addr )
22182238 }
22192239
2220- tr , err := NewClientTransport (ctx , context .Background (), addr , ConnectOptions {Dialer : dialer }, func () {}, func (GoAwayReason ) {}, func () {})
2240+ copts := ConnectOptions {
2241+ Dialer : dialer ,
2242+ ChannelzParentID : channelz .NewIdentifierForTesting (channelz .RefSubChannel , time .Now ().Unix (), nil ),
2243+ }
2244+ tr , err := NewClientTransport (ctx , context .Background (), addr , copts , func () {}, func (GoAwayReason ) {}, func () {})
22212245 if err != nil {
22222246 t .Fatalf ("NewClientTransport(): %v" , err )
22232247 }
0 commit comments