-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci][coro_rpc] fix ci, add parallel test for coro_rpc
- Loading branch information
1 parent
0868878
commit f1e2b7a
Showing
7 changed files
with
180 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include <future> | ||
#include <memory> | ||
#include <vector> | ||
#include <ylt/coro_rpc/coro_rpc_client.hpp> | ||
#include <ylt/coro_rpc/coro_rpc_server.hpp> | ||
|
||
#include "async_simple/coro/Semaphore.h" | ||
#include "doctest.h" | ||
#include "ylt/coro_io/io_context_pool.hpp" | ||
#include "ylt/coro_rpc/impl/coro_rpc_client.hpp" | ||
#include "ylt/easylog.hpp" | ||
#include "ylt/easylog/record.hpp" | ||
using namespace async_simple::coro; | ||
std::string_view echo(std::string_view data) { return data; } | ||
TEST_CASE("test parall coro_rpc call") { | ||
int thread_cnt = 100; | ||
coro_rpc::coro_rpc_server server(thread_cnt, 9001); | ||
coro_io::io_context_pool pool(thread_cnt); | ||
std::thread thrd{[&] { | ||
pool.run(); | ||
}}; | ||
|
||
server.register_handler<echo>(); | ||
server.async_start(); | ||
int client_cnt = 500; | ||
int64_t work_cnt_tot = thread_cnt * client_cnt * 10; | ||
std::vector<std::unique_ptr<coro_rpc::coro_rpc_client>> clients; | ||
clients.resize(client_cnt); | ||
std::atomic<int> connected_cnt = 0; | ||
std::atomic<int> work_cnt = 0; | ||
std::promise<void> p, p2; | ||
for (auto& cli : clients) { | ||
cli = std::make_unique<coro_rpc::coro_rpc_client>(); | ||
cli->connect("127.0.0.1", "9001", std::chrono::seconds{5}) | ||
.via(pool.get_executor()) | ||
.start([&](auto&&) { | ||
if (++connected_cnt == client_cnt) { | ||
p.set_value(); | ||
} | ||
}); | ||
} | ||
p.get_future().wait(); | ||
for (int i = 0; i < work_cnt_tot; ++i) { | ||
[](coro_rpc::coro_rpc_client& cli) -> Lazy<void> { | ||
if (!cli.has_closed()) { | ||
auto future_resp = co_await cli.send_request<echo>("hello"); | ||
auto result = co_await std::move(future_resp); | ||
if (result.has_value()) { | ||
CHECK(result.value().result() == "hello"); | ||
} | ||
} | ||
}(*clients[i % client_cnt]) | ||
.via(pool.get_executor()) | ||
.start([&](auto&&) { | ||
auto i = ++work_cnt; | ||
if (i == work_cnt_tot) { | ||
p2.set_value(); | ||
} | ||
}); | ||
} | ||
p2.get_future().wait(); | ||
pool.stop(); | ||
thrd.join(); | ||
}; | ||
|
||
TEST_CASE("test parall coro_rpc call2") { | ||
int thread_cnt = 100; | ||
coro_rpc::coro_rpc_server server(thread_cnt, 9001); | ||
coro_io::io_context_pool pool(thread_cnt); | ||
std::thread thrd{[&] { | ||
pool.run(); | ||
}}; | ||
server.register_handler<echo>(); | ||
server.async_start(); | ||
int client_cnt = 500; | ||
std::vector<std::unique_ptr<coro_rpc::coro_rpc_client>> clients; | ||
clients.resize(client_cnt); | ||
std::atomic<int> work_cnt = 0; | ||
std::promise<void> p; | ||
for (auto& cli : clients) { | ||
cli = std::make_unique<coro_rpc::coro_rpc_client>(); | ||
cli->connect("127.0.0.1", "9001", std::chrono::seconds{5}) | ||
.via(pool.get_executor()) | ||
.start([&](auto&&) { | ||
[](coro_rpc::coro_rpc_client& cli) -> Lazy<void> { | ||
for (int i = 0; i < 1000; ++i) | ||
if (!cli.has_closed()) { | ||
auto result = co_await cli.call<echo>("hello"); | ||
if (result.has_value()) { | ||
CHECK(result.value() == "hello"); | ||
} | ||
} | ||
}(*cli) | ||
.start([&](auto&&) { | ||
auto i = ++work_cnt; | ||
if (i == client_cnt) { | ||
p.set_value(); | ||
} | ||
}); | ||
}); | ||
} | ||
p.get_future().wait(); | ||
pool.stop(); | ||
thrd.join(); | ||
}; |