#include #include #include #include #include #include "common/utils/Duration.h" #include "common/utils/DynamicCoroutinesPool.h" #include "tests/GtestHelpers.h" namespace hf3fs::test { namespace { TEST(TestDynamicCoroutinesPool, Normal) { DynamicCoroutinesPool::Config config; config.set_coroutines_num(8); DynamicCoroutinesPool pool(config); ASSERT_OK(pool.start()); ASSERT_OK(pool.stopAndJoin()); DynamicCoroutinesPool{config}; } TEST(TestDynamicCoroutinesPool, ManyTasks) { constexpr auto N = 200; constexpr auto M = 64; DynamicCoroutinesPool::Config config; config.set_coroutines_num(M); DynamicCoroutinesPool pool(config); ASSERT_OK(pool.start()); folly::coro::Baton baton; std::atomic cnt{}; std::atomic current{}; for (auto i = 0; i < N; ++i) { pool.enqueue(folly::coro::co_invoke([&]() -> CoTask { auto now = ++current; CO_ASSERT_LE(now, M); co_await folly::coro::sleep(50_ms); if (++cnt == N) { baton.post(); } --current; })); } folly::coro::blockingWait(baton); } TEST(TestDynamicCoroutinesPool, HotUpdated) { constexpr auto N = 64; DynamicCoroutinesPool::Config config; config.set_coroutines_num(1); DynamicCoroutinesPool pool(config); ASSERT_OK(pool.start()); folly::coro::Baton baton; std::atomic cnt{}; std::atomic current{}; for (auto i = 0; i < N; ++i) { pool.enqueue(folly::coro::co_invoke([&]() -> CoTask { auto now = ++current; config.set_coroutines_num(now + 1); config.update(toml::table{}, true); co_await folly::coro::sleep(50_ms); if (++cnt == N) { baton.post(); } --current; })); } folly::coro::blockingWait(baton); } } // namespace } // namespace hf3fs::test