MCPcopy Create free account
hub / github.com/David-Haim/concurrencpp / test_runtime_constructor

Method test_runtime_constructor

test/source/tests/runtime_tests.cpp:35–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33} // namespace concurrencpp::tests
34
35void concurrencpp::tests::test_runtime_constructor() {
36 concurrencpp::runtime_options opts;
37 opts.max_cpu_threads = 3;
38 opts.max_thread_pool_executor_waiting_time = std::chrono::milliseconds(12345);
39
40 opts.max_background_threads = 7;
41 opts.max_background_executor_waiting_time = std::chrono::milliseconds(54321);
42
43 std::atomic_size_t thread_started_callback_invocations_num = 0;
44 std::atomic_size_t thread_terminated_callback_invocations_num = 0;
45
46 opts.thread_started_callback = [&thread_started_callback_invocations_num](std::string_view thread_name) {
47 assert_false(thread_name.empty());
48 ++thread_started_callback_invocations_num;
49 };
50
51 opts.thread_terminated_callback = [&thread_terminated_callback_invocations_num](std::string_view thread_name) {
52 assert_false(thread_name.empty());
53 ++thread_terminated_callback_invocations_num;
54 };
55
56 concurrencpp::runtime runtime(opts);
57 auto dummy_ex = runtime.make_executor<dummy_executor>("dummy_executor", 1, 4.4f);
58 assert_true(static_cast<bool>(runtime.inline_executor()));
59 assert_true(static_cast<bool>(runtime.thread_executor()));
60 assert_true(static_cast<bool>(runtime.thread_pool_executor()));
61 assert_true(static_cast<bool>(runtime.background_executor()));
62 assert_true(static_cast<bool>(dummy_ex));
63
64 assert_false(runtime.inline_executor()->shutdown_requested());
65 assert_false(runtime.thread_executor()->shutdown_requested());
66 assert_false(runtime.thread_pool_executor()->shutdown_requested());
67 assert_false(runtime.background_executor()->shutdown_requested());
68 assert_false(dummy_ex->shutdown_requested());
69
70 assert_equal(runtime.thread_pool_executor()->max_concurrency_level(), opts.max_cpu_threads);
71 assert_equal(runtime.thread_pool_executor()->max_worker_idle_time(), opts.max_thread_pool_executor_waiting_time);
72 assert_equal(runtime.background_executor()->max_concurrency_level(), opts.max_background_threads);
73 assert_equal(runtime.background_executor()->max_worker_idle_time(), opts.max_background_executor_waiting_time);
74
75 auto test_runtime_executor = [&thread_started_callback_invocations_num,
76 &thread_terminated_callback_invocations_num](std::shared_ptr<executor> executor) {
77 thread_started_callback_invocations_num = 0;
78 thread_terminated_callback_invocations_num = 0;
79
80 executor
81 ->submit([&thread_started_callback_invocations_num, &thread_terminated_callback_invocations_num]() {
82 assert_equal(thread_started_callback_invocations_num, 1);
83 assert_equal(thread_terminated_callback_invocations_num, 0);
84 })
85 .get();
86
87 executor->shutdown();
88 assert_equal(thread_started_callback_invocations_num, 1);
89 assert_equal(thread_terminated_callback_invocations_num, 1);
90 };
91
92 test_runtime_executor(runtime.thread_executor());

Callers

nothing calls this directly

Calls 13

assert_falseFunction · 0.85
assert_trueFunction · 0.85
assert_equalFunction · 0.85
inline_executorMethod · 0.80
background_executorMethod · 0.80
emptyMethod · 0.45
thread_executorMethod · 0.45
thread_pool_executorMethod · 0.45
shutdown_requestedMethod · 0.45
max_concurrency_levelMethod · 0.45
max_worker_idle_timeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected