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

Method TestCZChannelConnectivityState

test/channelz_test.go:1951–2006  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1949}
1950
1951func (s) TestCZChannelConnectivityState(t *testing.T) {
1952 e := tcpClearRREnv
1953 te := newTest(t, e)
1954 te.startServer(&testServer{security: e.security})
1955 r := manual.NewBuilderWithScheme("whatever")
1956 r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: te.srvAddr}}})
1957 te.resolverScheme = r.Scheme()
1958 cc := te.clientConn(grpc.WithResolvers(r))
1959 defer te.tearDown()
1960 tc := testgrpc.NewTestServiceClient(cc)
1961 // make sure the connection is up
1962 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1963 defer cancel()
1964 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil {
1965 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
1966 }
1967 te.srv.Stop()
1968
1969 if err := verifyResultWithDelay(func() (bool, error) {
1970 tcs, _ := channelz.GetTopChannels(0, 0)
1971 if len(tcs) != 1 {
1972 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
1973 }
1974
1975 var ready, connecting, transient int
1976 t.Log("Channel trace events seen so far...")
1977 for _, e := range tcs[0].Trace().Events {
1978 t.Log(e.Desc)
1979 if strings.Contains(e.Desc, fmt.Sprintf("Channel Connectivity change to %v", connectivity.Ready)) {
1980 ready++
1981 }
1982 if strings.Contains(e.Desc, fmt.Sprintf("Channel Connectivity change to %v", connectivity.Connecting)) {
1983 connecting++
1984 }
1985 if strings.Contains(e.Desc, fmt.Sprintf("Channel Connectivity change to %v", connectivity.TransientFailure)) {
1986 transient++
1987 }
1988 }
1989
1990 // example:
1991 // Channel Created
1992 // Addresses resolved (from empty address state): "localhost:40467"
1993 // SubChannel (id: 4[]) Created
1994 // Channel's connectivity state changed to CONNECTING
1995 // Channel's connectivity state changed to READY
1996 // Channel's connectivity state changed to TRANSIENT_FAILURE
1997 // Channel's connectivity state changed to CONNECTING
1998 // Channel's connectivity state changed to TRANSIENT_FAILURE
1999 if ready != 1 || connecting < 1 || transient < 1 {
2000 return false, fmt.Errorf("got: ready = %d, connecting = %d, transient = %d, want: 1, >=1, >=1", ready, connecting, transient)
2001 }
2002 return true, nil
2003 }); err != nil {
2004 t.Fatal(err)
2005 }
2006}
2007
2008func (s) TestCZTraceOverwriteChannelDeletion(t *testing.T) {

Callers

nothing calls this directly

Calls 15

EmptyCallMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
GetTopChannelsFunction · 0.92
InitialStateMethod · 0.80
newTestFunction · 0.70
verifyResultWithDelayFunction · 0.70
SchemeMethod · 0.65
FatalfMethod · 0.65
StopMethod · 0.65
ErrorfMethod · 0.65
LogMethod · 0.65

Tested by

no test coverage detected