Skip to content

Commit

Permalink
[coro_rpc] fix server constructor (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle authored Dec 2, 2024
1 parent 1cb2da9 commit 40f6cf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 2 additions & 3 deletions include/ylt/coro_rpc/impl/coro_rpc_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ class coro_rpc_server_base {
init_address(std::move(address));
}

coro_rpc_server_base(size_t thread_num = std::thread::hardware_concurrency(),
std::string address = "0.0.0.0:9001",
coro_rpc_server_base(size_t thread_num, std::string address,
std::chrono::steady_clock::duration
conn_timeout_duration = std::chrono::seconds(0),
bool is_enable_tcp_no_delay = true)
Expand All @@ -102,7 +101,7 @@ class coro_rpc_server_base {
init_address(std::move(address));
}

coro_rpc_server_base(const server_config &config = server_config{})
coro_rpc_server_base(const server_config &config)
: pool_(config.thread_num),
acceptor_(pool_.get_executor()->get_asio_executor()),
port_(config.port),
Expand Down
18 changes: 11 additions & 7 deletions src/coro_io/tests/test_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,26 @@ void hello() {}

TEST_CASE("test server down") {
async_simple::coro::syncAwait([]() -> async_simple::coro::Lazy<void> {
coro_rpc::coro_rpc_server server1(1, 58801);
coro_rpc::coro_rpc_server server1(1, 0);
server1.register_handler<hello>();
auto res = server1.async_start();
REQUIRE_MESSAGE(!res.hasResult(), "server start failed");
coro_rpc::coro_rpc_server server2(1, 58802);
auto port1 = server1.port();
coro_rpc::coro_rpc_server server2(1, 0);
server2.register_handler<hello>();
auto res2 = server2.async_start();
REQUIRE_MESSAGE(!res2.hasResult(), "server start failed");
auto hosts =
std::vector<std::string_view>{"127.0.0.1:58801", "127.0.0.1:58802"};

auto port2 = server2.port();
auto hosts = std::vector<std::string>{"127.0.0.1:" + std::to_string(port1),
"127.0.0.1:" + std::to_string(port2)};
auto host_view = std::vector<std::string_view>{hosts[0], hosts[1]};
auto config = coro_io::client_pool<coro_rpc::coro_rpc_client>::pool_config{
.connect_retry_count = 0,
.reconnect_wait_time = std::chrono::milliseconds{0},
.host_alive_detect_duration = std::chrono::milliseconds{500}};
auto load_blancer =
coro_io::load_blancer<coro_rpc::coro_rpc_client>::create(hosts,
coro_io::load_blancer<coro_rpc::coro_rpc_client>::create(host_view,
{config});

for (int i = 0; i < 100; ++i) {
Expand Down Expand Up @@ -259,7 +263,7 @@ TEST_CASE("test server down") {
}
}

coro_rpc::coro_rpc_server server3(1, 58801);
coro_rpc::coro_rpc_server server3(1, port1);
server3.register_handler<hello>();
auto res3 = server3.async_start();
REQUIRE_MESSAGE(!res3.hasResult(), "server start failed");
Expand All @@ -276,7 +280,7 @@ TEST_CASE("test server down") {
CHECK(res.has_value());
}
}
coro_rpc::coro_rpc_server server4(1, 58802);
coro_rpc::coro_rpc_server server4(1, port2);
server4.register_handler<hello>();
auto res4 = server4.async_start();
REQUIRE_MESSAGE(!res4.hasResult(), "server start failed");
Expand Down

0 comments on commit 40f6cf7

Please sign in to comment.