(t *testing.T)
| 1376 | } |
| 1377 | |
| 1378 | func (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 | |
| 1420 | var cipherSuites = []string{ |
| 1421 | "TLS_RSA_WITH_RC4_128_SHA", |
nothing calls this directly
no test coverage detected