...

Source file src/google.golang.org/grpc/test/channelz_linux_test.go

Documentation: google.golang.org/grpc/test

     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  	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