From: Kefu Chai Date: Thu, 30 Apr 2020 02:44:10 +0000 (+0800) Subject: test/crimson: minimize the lexical scope of thread pool X-Git-Tag: v16.1.0~2441^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F34874%2Fhead;p=ceph.git 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 --- diff --git a/src/test/crimson/test_thread_pool.cc b/src/test/crimson/test_thread_pool.cc index c3ab6fdb0e1b..962470e3b69c 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); }); }); }