]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/crimson/test_alienstore_thread_pool.cc
4 #include <seastar/core/app-template.hh>
5 #include "common/ceph_argparse.h"
6 #include "crimson/common/config_proxy.h"
7 #include "crimson/os/alienstore/thread_pool.h"
8 #include "include/msgr.h"
10 using namespace std::chrono_literals
;
11 using ThreadPool
= crimson::os::ThreadPool
;
12 using crimson::common::local_conf
;
14 seastar::future
<> test_accumulate(ThreadPool
& tp
) {
15 static constexpr auto N
= 5;
16 static constexpr auto M
= 1;
17 auto slow_plus
= [&tp
](int i
) {
18 return tp
.submit(::rand() % 2, [=] {
19 std::this_thread::sleep_for(10ns
);
23 return seastar::map_reduce(
24 boost::irange(0, N
), slow_plus
, 0, std::plus
{}).then([] (int sum
) {
25 auto r
= boost::irange(0 + M
, N
+ M
);
26 if (sum
!= std::accumulate(r
.begin(), r
.end(), 0)) {
27 throw std::runtime_error("test_accumulate failed");
32 seastar::future
<> test_void_return(ThreadPool
& tp
) {
33 return tp
.submit(::rand() % 2, [=] {
34 std::this_thread::sleep_for(10ns
);
38 int main(int argc
, char** argv
)
40 seastar::app_template app
;
41 return app
.run(argc
, argv
, [] {
42 std::vector
<const char*> args
;
44 std::string conf_file_list
;
45 auto init_params
= ceph_argparse_early_args(args
,
46 CEPH_ENTITY_TYPE_CLIENT
,
49 return crimson::common::sharded_conf().start(init_params
.name
, cluster
)
50 .then([conf_file_list
] {
51 return local_conf().parse_config_files(conf_file_list
);
53 return seastar::do_with(std::make_unique
<crimson::os::ThreadPool
>(2, 128, seastar::resource::cpuset
{0}),
55 return tp
->start().then([&tp
] {
56 return test_accumulate(*tp
);
58 return test_void_return(*tp
);
64 return crimson::common::sharded_conf().stop();
65 }).handle_exception([](auto e
) {
66 std::cerr
<< "Error: " << e
<< std::endl
;
67 seastar::engine().exit(1);
74 * compile-command: "make -j4 \
76 * unittest_seastar_thread_pool"