From 4c81db2abfd3ceb4df5c1ccacf8e53b0f0b0af70 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 30 Apr 2020 10:44:10 +0800 Subject: [PATCH] test/crimson: minimize the lexical scope of thread pool to show the typical use case of thread pool in a better manner: thread pool can be initialized *in* a seastar application. also move `handle_exception()` out to catch all exceptions throwns in the seastar app. Signed-off-by: Kefu Chai --- src/test/crimson/test_thread_pool.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/test/crimson/test_thread_pool.cc b/src/test/crimson/test_thread_pool.cc index c3ab6fdb0e1..962470e3b69 100644 --- a/src/test/crimson/test_thread_pool.cc +++ b/src/test/crimson/test_thread_pool.cc @@ -37,9 +37,8 @@ seastar::future<> test_void_return(ThreadPool& tp) { int main(int argc, char** argv) { - std::unique_ptr tp; seastar::app_template app; - return app.run(argc, argv, [&tp] { + return app.run(argc, argv, [] { std::vector args; std::string cluster; std::string conf_file_list; @@ -50,20 +49,22 @@ int main(int argc, char** argv) return crimson::common::sharded_conf().start(init_params.name, cluster) .then([conf_file_list] { return local_conf().parse_config_files(conf_file_list); - }).then([&tp] { - tp = std::make_unique(2, 128, 0); - return tp->start().then([&tp] { - return test_accumulate(*tp); - }).then([&tp] { - return test_void_return(*tp); - }).handle_exception([](auto e) { - std::cerr << "Error: " << e << std::endl; - seastar::engine().exit(1); - }).finally([&tp] { - return tp->stop(); + }).then([] { + return seastar::do_with(std::make_unique(2, 128, 0), + [](auto& tp) { + return tp->start().then([&tp] { + return test_accumulate(*tp); + }).then([&tp] { + return test_void_return(*tp); + }).finally([&tp] { + return tp->stop(); + }); }); }).finally([] { return crimson::common::sharded_conf().stop(); + }).handle_exception([](auto e) { + std::cerr << "Error: " << e << std::endl; + seastar::engine().exit(1); }); }); } -- 2.39.5