...
1
18
19 package test
20
21 import (
22 "testing"
23 "time"
24
25 "google.golang.org/grpc/internal/channelz"
26
27 testgrpc "google.golang.org/grpc/interop/grpc_testing"
28 )
29
30 func (s) TestCZSocketMetricsSocketOption(t *testing.T) {
31 envs := []env{tcpClearRREnv, tcpTLSRREnv}
32 for _, e := range envs {
33 testCZSocketMetricsSocketOption(t, e)
34 }
35 }
36
37 func 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 }
95 }
96
View as plain text