@@ -434,8 +434,7 @@ func setUp(t *testing.T, port int, ht hType) (*server, *http2Client, func()) {
434434func setUpWithOptions (t * testing.T , port int , sc * ServerConfig , ht hType , copts ConnectOptions ) (* server , * http2Client , func ()) {
435435 server := setUpServerOnly (t , port , sc , ht )
436436 addr := resolver.Address {Addr : "localhost:" + server .port }
437- copts .ChannelzParent = channelz .RegisterSubChannel (- 1 , "test channel" )
438- t .Cleanup (func () { channelz .RemoveEntry (copts .ChannelzParent .ID ) })
437+ copts .ChannelzParent = channelzSubChannel (t )
439438
440439 connectCtx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (2 * time .Second ))
441440 ct , connErr := NewClientTransport (connectCtx , context .Background (), addr , copts , func (GoAwayReason ) {})
@@ -1321,9 +1320,8 @@ func (s) TestClientHonorsConnectContext(t *testing.T) {
13211320 connectCtx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
13221321 time .AfterFunc (100 * time .Millisecond , cancel )
13231322
1324- parent := channelz . RegisterSubChannel ( - 1 , "test channel" )
1323+ parent := channelzSubChannel ( t )
13251324 copts := ConnectOptions {ChannelzParent : parent }
1326- defer channelz .RemoveEntry (parent .ID )
13271325 _ , err = NewClientTransport (connectCtx , context .Background (), resolver.Address {Addr : lis .Addr ().String ()}, copts , func (GoAwayReason ) {})
13281326 if err == nil {
13291327 t .Fatalf ("NewClientTransport() returned successfully; wanted error" )
@@ -1414,8 +1412,7 @@ func (s) TestClientWithMisbehavedServer(t *testing.T) {
14141412 connectCtx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (2 * time .Second ))
14151413 defer cancel ()
14161414
1417- parent := channelz .RegisterSubChannel (- 1 , "test channel" )
1418- defer channelz .RemoveEntry (parent .ID )
1415+ parent := channelzSubChannel (t )
14191416 copts := ConnectOptions {ChannelzParent : parent }
14201417 ct , err := NewClientTransport (connectCtx , context .Background (), resolver.Address {Addr : lis .Addr ().String ()}, copts , func (GoAwayReason ) {})
14211418 if err != nil {
@@ -2425,9 +2422,8 @@ func (s) TestClientHandshakeInfo(t *testing.T) {
24252422
24262423 copts := ConnectOptions {
24272424 TransportCredentials : creds ,
2428- ChannelzParent : channelz . RegisterSubChannel ( - 1 , "test subchannel" ),
2425+ ChannelzParent : channelzSubChannel ( t ),
24292426 }
2430- defer channelz .RemoveEntry (copts .ChannelzParent .ID )
24312427 tr , err := NewClientTransport (ctx , context .Background (), addr , copts , func (GoAwayReason ) {})
24322428 if err != nil {
24332429 t .Fatalf ("NewClientTransport(): %v" , err )
@@ -2467,9 +2463,8 @@ func (s) TestClientHandshakeInfoDialer(t *testing.T) {
24672463
24682464 copts := ConnectOptions {
24692465 Dialer : dialer ,
2470- ChannelzParent : channelz . RegisterSubChannel ( - 1 , "test subchannel" ),
2466+ ChannelzParent : channelzSubChannel ( t ),
24712467 }
2472- defer channelz .RemoveEntry (copts .ChannelzParent .ID )
24732468 tr , err := NewClientTransport (ctx , context .Background (), addr , copts , func (GoAwayReason ) {})
24742469 if err != nil {
24752470 t .Fatalf ("NewClientTransport(): %v" , err )
0 commit comments