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

Function testCZSocketMetricsSocketOption

test/channelz_linux_test.go:37–95  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

35}
36
37func testCZSocketMetricsSocketOption(t *testing.T, e env) {
38 te := newTest(t, e)
39 te.startServer(&testServer{security: e.security})
40 defer te.tearDown()
41 cc := te.clientConn()
42 tc := testgrpc.NewTestServiceClient(cc)
43 doSuccessfulUnaryCall(tc, t)
44
45 time.Sleep(10 * time.Millisecond)
46 ss, _ := channelz.GetServers(0, 0)
47 if len(ss) != 1 {
48 t.Fatalf("There should be one server, not %d", len(ss))
49 }
50 skts := ss[0].ListenSockets()
51 if len(skts) != 1 {
52 t.Fatalf("There should be one listen socket, not %d", len(skts))
53 }
54 for id := range skts {
55 sm := channelz.GetSocket(id)
56 if sm == nil || sm.SocketOptions == nil {
57 t.Fatalf("Unable to get server listen socket options")
58 }
59 }
60 ns, _ := channelz.GetServerSockets(ss[0].ID, 0, 0)
61 if len(ns) != 1 {
62 t.Fatalf("There should be one server normal socket, not %d", len(ns))
63 }
64 if ns[0] == nil || ns[0].SocketOptions == nil {
65 t.Fatalf("Unable to get server normal socket options")
66 }
67
68 tchan, _ := channelz.GetTopChannels(0, 0)
69 if len(tchan) != 1 {
70 t.Fatalf("There should only be one top channel, not %d", len(tchan))
71 }
72 subChans := tchan[0].SubChans()
73 if len(subChans) != 1 {
74 t.Fatalf("There should only be one subchannel under top channel %d, not %d", tchan[0].ID, len(subChans))
75 }
76 var id int64
77 for id = range subChans {
78 break
79 }
80 sc := channelz.GetSubChannel(id)
81 if sc == nil {
82 t.Fatalf("There should only be one socket under subchannel %d, not 0", id)
83 }
84 skts = sc.Sockets()
85 if len(skts) != 1 {
86 t.Fatalf("There should only be one socket under subchannel %d, not %d", sc.ID, len(skts))
87 }
88 for id = range skts {
89 break
90 }
91 skt := channelz.GetSocket(id)
92 if skt == nil || skt.SocketOptions == nil {
93 t.Fatalf("Unable to get client normal socket options")
94 }

Callers 1

Calls 14

GetServersFunction · 0.92
GetSocketFunction · 0.92
GetServerSocketsFunction · 0.92
GetTopChannelsFunction · 0.92
GetSubChannelFunction · 0.92
doSuccessfulUnaryCallFunction · 0.85
ListenSocketsMethod · 0.80
SubChansMethod · 0.80
SocketsMethod · 0.80
newTestFunction · 0.70
FatalfMethod · 0.65
startServerMethod · 0.45

Tested by

no test coverage detected