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

Method TestCZServerSocketMetricsKeepAlive

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

Source from the content-addressed store, hash-verified

1376}
1377
1378func (s) TestCZServerSocketMetricsKeepAlive(t *testing.T) {
1379 defer func(t time.Duration) { internal.KeepaliveMinServerPingTime = t }(internal.KeepaliveMinServerPingTime)
1380 internal.KeepaliveMinServerPingTime = 50 * time.Millisecond
1381
1382 e := tcpClearRREnv
1383 te := newTest(t, e)
1384 // We setup the server keepalive parameters to send one keepalive every
1385 // 50ms, and verify that the actual number of keepalives is very close to
1386 // Time/50ms. We had a bug wherein the server was sending one keepalive
1387 // every [Time+Timeout] instead of every [Time] period, and since Timeout
1388 // is configured to a high value here, we should be able to verify that the
1389 // fix works with the above mentioned logic.
1390 kpOption := grpc.KeepaliveParams(keepalive.ServerParameters{
1391 Time: 50 * time.Millisecond,
1392 Timeout: 5 * time.Second,
1393 })
1394 te.customServerOptions = append(te.customServerOptions, kpOption)
1395 te.startServer(&testServer{security: e.security})
1396 defer te.tearDown()
1397 cc := te.clientConn()
1398
1399 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1400 defer cancel()
1401 testutils.AwaitState(ctx, t, cc, connectivity.Ready)
1402
1403 // Allow about 5 pings to happen (250ms/50ms).
1404 time.Sleep(255 * time.Millisecond)
1405
1406 ss, _ := channelz.GetServers(0, 0)
1407 if len(ss) != 1 {
1408 t.Fatalf("there should be one server, not %d", len(ss))
1409 }
1410 ns, _ := channelz.GetServerSockets(ss[0].ID, 0, 0)
1411 if len(ns) != 1 {
1412 t.Fatalf("there should be one server normal socket, not %d", len(ns))
1413 }
1414 const wantMin, wantMax = 3, 7
1415 if got := ns[0].SocketMetrics.KeepAlivesSent.Load(); got < wantMin || got > wantMax {
1416 t.Fatalf("got keepalivesCount: %v, want keepalivesCount: [%v,%v]", got, wantMin, wantMax)
1417 }
1418}
1419
1420var cipherSuites = []string{
1421 "TLS_RSA_WITH_RC4_128_SHA",

Callers

nothing calls this directly

Calls 10

KeepaliveParamsFunction · 0.92
AwaitStateFunction · 0.92
GetServersFunction · 0.92
GetServerSocketsFunction · 0.92
newTestFunction · 0.70
FatalfMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45
clientConnMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected