This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit a5eb21270f9b5b13ffdb6184fc3e82e04450ddc5 Author: Alexey Serbin <[email protected]> AuthorDate: Fri Apr 5 19:23:12 2024 -0700 [rpc-test] make RpcPendingConnectionsMetric more stable I noticed that on very fast machines the RpcPendingConnectionsMetric scenario would rarely fail (~1 time per 500 runs) because the sock_diag() netlink facility seemingly reported stale data, i.e. reported one connection was pending while the only attempted connection had already been accepted by the server and even closed by the client. With this test no flakiness has been observed in more than 50K runs of the scenario. Change-Id: If8e66c471452b1e04c84cf2d5c979578c287b4fa Reviewed-on: http://gerrit.cloudera.org:8080/21251 Tested-by: Alexey Serbin <[email protected]> Reviewed-by: Mahesh Reddy <[email protected]> Reviewed-by: Abhishek Chennaka <[email protected]> --- src/kudu/rpc/rpc-test.cc | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/kudu/rpc/rpc-test.cc b/src/kudu/rpc/rpc-test.cc index 3bef361d0..74284735c 100644 --- a/src/kudu/rpc/rpc-test.cc +++ b/src/kudu/rpc/rpc-test.cc @@ -1461,16 +1461,13 @@ TEST_P(TestRpc, AcceptorDispatchingTimesMetric) { } // Basic verification of the 'rpc_pending_connections' metric. +// The number of pending connections is properly reported on Linux; on other +// platforms that don't support sock_diag() netlink facility (e.g., macOS) +// the metric should report -1. TEST_P(TestRpc, RpcPendingConnectionsMetric) { Sockaddr server_addr; ASSERT_OK(StartTestServer(&server_addr)); - { - Socket socket; - ASSERT_OK(socket.Init(server_addr.family(), /*flags=*/0)); - ASSERT_OK(socket.Connect(server_addr)); - } - // Get the reference to already registered metric with the proper callback // to fetch the necessary information. The { 'return -3'; } fake callback // is to make sure the actual gauge returns a proper value, @@ -1479,9 +1476,26 @@ TEST_P(TestRpc, RpcPendingConnectionsMetric) { METRIC_rpc_pending_connections.InstantiateFunctionGauge( server_messenger_->metric_entity(), []() { return -3; }); - // There should be no connection pending -- the only received connection - // request has been handled already above. The number of pending connections - // is properly reported at Linux only as of now; on macOS it should report -1. + // No connection attempts have been made yet. +#if defined(__linux__) + ASSERT_EQ(0, pending_connections_gauge->value()); +#else + ASSERT_EQ(-1, pending_connections_gauge->value()); +#endif + + { + Socket socket; + ASSERT_OK(socket.Init(server_addr.family(), /*flags=*/0)); + ASSERT_OK(socket.Connect(server_addr)); + } + + // A small pause below is to avoid reading 1 from the metric: it's not quite + // clear why the sock_diag() netlink facility reports stale data on very fast + // machines in rare cases. + SleepFor(MonoDelta::FromMilliseconds(10)); + + // At this point, there should be no connection pending: the only received + // connection request has already been handled above. #if defined(__linux__) ASSERT_EQ(0, pending_connections_gauge->value()); #else
