Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coro_rpc] fix server constructor #837

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading