From e26e90699f17166fd90a1f664dcaf6e79e476362 Mon Sep 17 00:00:00 2001 From: "Zezheng.Li" Date: Thu, 27 Jul 2023 15:53:18 +0800 Subject: [PATCH] fix crash --- src/coro_io/tests/test_client_pool.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/coro_io/tests/test_client_pool.cpp b/src/coro_io/tests/test_client_pool.cpp index 93c8ecfde..bba91a931 100644 --- a/src/coro_io/tests/test_client_pool.cpp +++ b/src/coro_io/tests/test_client_pool.cpp @@ -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 &cv, SpinLock &lock, - std::function user_op = - [](auto &client) { - }) -> async_simple::coro::Lazy { +template +async_simple::coro::Lazy event( + int lim, coro_io::client_pool &pool, ConditionVariable &cv, + SpinLock &lock, + std::function user_op = + [](auto &client) { + }) { std::vector> 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 { + &user_op](T &client) -> async_simple::coro::Lazy { user_op(client); auto l = co_await lock.coScopedLock(); if (++cnt < lim) { @@ -58,7 +59,8 @@ auto event = co_return; }; auto backer = [&cv, &lock, &cnt, &lim]( - auto &pool, auto op) -> async_simple::coro::Lazy { + coro_io::client_pool &pool, + auto op) -> async_simple::coro::Lazy { async_simple::Promise p; auto res = co_await pool.send_request(op); if (!res.has_value()) { @@ -152,7 +154,7 @@ TEST_CASE("test reconnect") { struct mock_client : public coro_rpc::coro_rpc_client { async_simple::coro::Lazy 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; @@ -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(100, *pool, cv, lock); CHECK(res); CHECK(pool->free_client_count() == 100); auto dur = std::chrono::steady_clock::now() - tp;