google.golang.org/grpc@v1.62.1/test/channelz_linux_test.go (about) 1 /* 2 * 3 * Copyright 2018 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 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 if len(ss[0].ListenSockets) != 1 { 51 t.Fatalf("There should be one listen socket, not %d", len(ss[0].ListenSockets)) 52 } 53 for id := range ss[0].ListenSockets { 54 sm := channelz.GetSocket(id) 55 if sm == nil || sm.SocketData == nil || sm.SocketData.SocketOptions == nil { 56 t.Fatalf("Unable to get server listen socket options") 57 } 58 } 59 ns, _ := channelz.GetServerSockets(ss[0].ID, 0, 0) 60 if len(ns) != 1 { 61 t.Fatalf("There should be one server normal socket, not %d", len(ns)) 62 } 63 if ns[0] == nil || ns[0].SocketData == nil || ns[0].SocketData.SocketOptions == nil { 64 t.Fatalf("Unable to get server normal socket options") 65 } 66 67 tchan, _ := channelz.GetTopChannels(0, 0) 68 if len(tchan) != 1 { 69 t.Fatalf("There should only be one top channel, not %d", len(tchan)) 70 } 71 if len(tchan[0].SubChans) != 1 { 72 t.Fatalf("There should only be one subchannel under top channel %d, not %d", tchan[0].ID, len(tchan[0].SubChans)) 73 } 74 var id int64 75 for id = range tchan[0].SubChans { 76 break 77 } 78 sc := channelz.GetSubChannel(id) 79 if sc == nil { 80 t.Fatalf("There should only be one socket under subchannel %d, not 0", id) 81 } 82 if len(sc.Sockets) != 1 { 83 t.Fatalf("There should only be one socket under subchannel %d, not %d", sc.ID, len(sc.Sockets)) 84 } 85 for id = range sc.Sockets { 86 break 87 } 88 skt := channelz.GetSocket(id) 89 if skt == nil || skt.SocketData == nil || skt.SocketData.SocketOptions == nil { 90 t.Fatalf("Unable to get client normal socket options") 91 } 92 }