Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Jul 27, 2023
1 parent 7885c14 commit e26e906
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/coro_io/tests/test_client_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@
#include "ylt/coro_rpc/impl/expected.hpp"
using namespace std::chrono_literals;
using namespace async_simple::coro;
auto event =
[](
int lim, auto &pool, ConditionVariable<SpinLock> &cv, SpinLock &lock,
std::function<void(coro_rpc::coro_rpc_client &client)> user_op =
[](auto &client) {
}) -> async_simple::coro::Lazy<bool> {
template <typename T = coro_rpc::coro_rpc_client>
async_simple::coro::Lazy<bool> event(
int lim, coro_io::client_pool<T> &pool, ConditionVariable<SpinLock> &cv,
SpinLock &lock,
std::function<void(coro_rpc::coro_rpc_client &client)> user_op =
[](auto &client) {
}) {
std::vector<RescheduleLazy<bool>> works;
int64_t cnt = 0;
for (int i = 0; i < lim; ++i) {
auto op = [&cnt, &lock, &cv, &lim,
&user_op](auto &client) -> async_simple::coro::Lazy<void> {
&user_op](T &client) -> async_simple::coro::Lazy<void> {
user_op(client);
auto l = co_await lock.coScopedLock();
if (++cnt < lim) {
Expand All @@ -58,7 +59,8 @@ auto event =
co_return;
};
auto backer = [&cv, &lock, &cnt, &lim](
auto &pool, auto op) -> async_simple::coro::Lazy<bool> {
coro_io::client_pool<T> &pool,
auto op) -> async_simple::coro::Lazy<bool> {
async_simple::Promise<bool> p;
auto res = co_await pool.send_request(op);
if (!res.has_value()) {
Expand Down Expand Up @@ -152,7 +154,7 @@ TEST_CASE("test reconnect") {
struct mock_client : public coro_rpc::coro_rpc_client {
async_simple::coro::Lazy<std::errc> reconnect(const std::string &hostname) {
auto ec = co_await this->coro_rpc::coro_rpc_client::reconnect(hostname);
if (ec!=std::errc{}) {
if (ec != std::errc{}) {
co_await coro_io::sleep_for(200ms);
}
co_return ec;
Expand All @@ -172,7 +174,7 @@ TEST_CASE("test reconnect retry wait time exinclude reconnect cost time") {
auto server_is_started = server.async_start();
REQUIRE(server_is_started);
});
auto res = co_await event(100, *pool, cv, lock);
auto res = co_await event<mock_client>(100, *pool, cv, lock);
CHECK(res);
CHECK(pool->free_client_count() == 100);
auto dur = std::chrono::steady_clock::now() - tp;
Expand Down

0 comments on commit e26e906

Please sign in to comment.