From af60c5d54dfc64191c19b2a5a7a20dc8050365b3 Mon Sep 17 00:00:00 2001 From: HeYuchen <377710264@qq.com> Date: Thu, 22 Oct 2020 14:32:57 +0800 Subject: [PATCH] refactor: reduce netprovider unit test executing time (#644) --- src/runtime/test/netprovider.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/runtime/test/netprovider.cpp b/src/runtime/test/netprovider.cpp index d3ca51392f..90e6bc1cc8 100644 --- a/src/runtime/test/netprovider.cpp +++ b/src/runtime/test/netprovider.cpp @@ -107,7 +107,7 @@ void rpc_server_response(dsn::message_ex *request) void wait_response() { while (wait_flag == 0) - std::this_thread::sleep_for(std::chrono::seconds(1)); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); } void rpc_client_session_send(rpc_session_ptr client_session, bool reject = false) @@ -272,9 +272,12 @@ TEST(tools_common, asio_network_provider_connection_threshold) error_code start_result; start_result = asio_network->start(RPC_CHANNEL_TCP, TEST_PORT, false); ASSERT_TRUE(start_result == ERR_OK); - asio_network->change_test_cfg_conn_threshold_per_ip(10); - for (int count = 0; count < 20; count++) { + auto CONN_THRESHOLD = 3; + asio_network->change_test_cfg_conn_threshold_per_ip(CONN_THRESHOLD); + + // not exceed threshold + for (int count = 0; count < CONN_THRESHOLD + 2; count++) { ddebug("client # %d", count); rpc_session_ptr client_session = asio_network->create_client_session(rpc_address("localhost", TEST_PORT)); @@ -283,18 +286,18 @@ TEST(tools_common, asio_network_provider_connection_threshold) rpc_client_session_send(client_session); client_session->close(); - std::this_thread::sleep_for(std::chrono::seconds(1)); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); } + // exceed threshold bool reject = false; - for (int count = 0; count < 20; count++) { - + for (int count = 0; count < CONN_THRESHOLD + 2; count++) { ddebug("client # %d", count); rpc_session_ptr client_session = asio_network->create_client_session(rpc_address("localhost", TEST_PORT)); client_session->connect(); - if (count >= 10) + if (count >= CONN_THRESHOLD) reject = true; rpc_client_session_send(client_session, reject); }