forked from reyreaud-l/threadpool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadpool_test.cpp
More file actions
58 lines (44 loc) · 1.42 KB
/
Copy paththreadpool_test.cpp
File metadata and controls
58 lines (44 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "threadpool_test.hpp"
TEST_F(ThreadPoolTest, SingleThreadStartStop)
{
ASSERT_FALSE(single_thread_pool->is_stopped());
single_thread_pool->stop();
ASSERT_TRUE(single_thread_pool->is_stopped());
}
TEST_F(ThreadPoolTest, SingleThreadSingleTask)
{
std::future<bool> result;
result = single_thread_pool->run([]() -> bool { return true; });
ASSERT_TRUE(result.valid());
ASSERT_TRUE(result.get());
}
TEST_F(ThreadPoolTest, SingleThreadMultipleTask)
{
std::size_t nb_tests = 10;
std::vector<std::future<bool>> results;
for (std::size_t i = 0; i < nb_tests; i++)
results.push_back(single_thread_pool->run([]() -> bool { return true; }));
for (std::size_t i = 0; i < nb_tests; i++)
ASSERT_TRUE(results[i].get());
}
TEST_F(ThreadPoolTest, MultipleThreadStartStop)
{
ASSERT_FALSE(multiple_thread_pool->is_stopped());
multiple_thread_pool->stop();
ASSERT_TRUE(multiple_thread_pool->is_stopped());
}
TEST_F(ThreadPoolTest, MultipleThreadSingleTask)
{
std::future<bool> result;
result = multiple_thread_pool->run([]() -> bool { return true; });
ASSERT_TRUE(result.get());
}
TEST_F(ThreadPoolTest, MultipleThreadMultipleTask)
{
std::size_t nb_tests = 2;
std::vector<std::future<bool>> results;
for (std::size_t i = 0; i < nb_tests; i++)
results.push_back(multiple_thread_pool->run([]() -> bool { return true; }));
for (std::size_t i = 0; i < nb_tests; i++)
ASSERT_TRUE(results[i].get());
}