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

Method TestGetChannel

channelz/service/service_test.go:312–413  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

310var logger = grpclog.Component("channelz")
311
312func (s) TestGetChannel(t *testing.T) {
313 refNames := []string{"top channel 1", "nested channel 1", "sub channel 2", "nested channel 3"}
314 cids := make([]*channelz.Channel, 3)
315 cids[0] = channelz.RegisterChannel(nil, refNames[0])
316 channelz.AddTraceEvent(logger, cids[0], 0, &channelz.TraceEvent{
317 Desc: "Channel Created",
318 Severity: channelz.CtInfo,
319 })
320
321 cids[1] = channelz.RegisterChannel(cids[0], refNames[1])
322 channelz.AddTraceEvent(logger, cids[1], 0, &channelz.TraceEvent{
323 Desc: "Channel Created",
324 Severity: channelz.CtInfo,
325 Parent: &channelz.TraceEvent{
326 Desc: fmt.Sprintf("Nested Channel(id:%d) created", cids[1].ID),
327 Severity: channelz.CtInfo,
328 },
329 })
330
331 subChan := channelz.RegisterSubChannel(cids[0], refNames[2])
332 channelz.AddTraceEvent(logger, subChan, 0, &channelz.TraceEvent{
333 Desc: "SubChannel Created",
334 Severity: channelz.CtInfo,
335 Parent: &channelz.TraceEvent{
336 Desc: fmt.Sprintf("SubChannel(id:%d) created", subChan.ID),
337 Severity: channelz.CtInfo,
338 },
339 })
340 defer channelz.RemoveEntry(subChan.ID)
341
342 cids[2] = channelz.RegisterChannel(cids[1], refNames[3])
343 channelz.AddTraceEvent(logger, cids[2], 0, &channelz.TraceEvent{
344 Desc: "Channel Created",
345 Severity: channelz.CtInfo,
346 Parent: &channelz.TraceEvent{
347 Desc: fmt.Sprintf("Nested Channel(id:%d) created", cids[2].ID),
348 Severity: channelz.CtInfo,
349 },
350 })
351 channelz.AddTraceEvent(logger, cids[0], 0, &channelz.TraceEvent{
352 Desc: fmt.Sprintf("Channel Connectivity change to %v", connectivity.Ready),
353 Severity: channelz.CtInfo,
354 })
355 channelz.AddTraceEvent(logger, cids[0], 0, &channelz.TraceEvent{
356 Desc: "Resolver returns an empty address list",
357 Severity: channelz.CtWarning,
358 })
359
360 for _, id := range cids {
361 defer channelz.RemoveEntry(id.ID)
362 }
363
364 svr := newCZServer()
365 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
366 defer cancel()
367 resp, _ := svr.GetChannel(ctx, &channelzpb.GetChannelRequest{ChannelId: cids[0].ID})
368 metrics := resp.GetChannel()
369 subChans := metrics.GetSubchannelRef()

Callers

nothing calls this directly

Calls 15

RegisterChannelFunction · 0.92
AddTraceEventFunction · 0.92
RegisterSubChannelFunction · 0.92
RemoveEntryFunction · 0.92
newCZServerFunction · 0.85
GetDescriptionMethod · 0.80
GetSeverityMethod · 0.80
GetChannelMethod · 0.65
FatalfMethod · 0.65
GetSubchannelRefMethod · 0.45
GetNameMethod · 0.45
GetSubchannelIdMethod · 0.45

Tested by

no test coverage detected