]> git.stg.codes - stg.git/blob - tests/test_async_pool.cpp
Update README.
[stg.git] / tests / test_async_pool.cpp
1 #define BOOST_TEST_MODULE STGSubscriptions
2
3 #include "async_pool.h"
4
5 #pragma GCC diagnostic push
6 #pragma GCC diagnostic ignored "-Wold-style-cast"
7 #pragma GCC diagnostic ignored "-Wunused-parameter"
8 #pragma GCC diagnostic ignored "-Wsign-compare"
9 #pragma GCC diagnostic ignored "-Wparentheses"
10 #include <boost/test/unit_test.hpp>
11 #pragma GCC diagnostic pop
12
13 namespace AsyncPoolST = STG::AsyncPoolST;
14
15 namespace
16 {
17
18 size_t counter = 0;
19
20 }
21
22 BOOST_AUTO_TEST_SUITE()
23
24 BOOST_AUTO_TEST_CASE(BeforeStart)
25 {
26     BOOST_CHECK_EQUAL(counter, 0);
27     AsyncPoolST::enqueue([](){ ++counter; });
28     std::this_thread::sleep_for(std::chrono::milliseconds(500));
29     BOOST_CHECK_EQUAL(counter, 0);
30 }
31
32 BOOST_AUTO_TEST_CASE(AfterStart)
33 {
34     BOOST_CHECK_EQUAL(counter, 0);
35     AsyncPoolST::start();
36     std::this_thread::sleep_for(std::chrono::milliseconds(500));
37     BOOST_CHECK_EQUAL(counter, 1);
38     AsyncPoolST::enqueue([](){ ++counter; });
39     std::this_thread::sleep_for(std::chrono::milliseconds(500));
40     BOOST_CHECK_EQUAL(counter, 2);
41 }
42
43 BOOST_AUTO_TEST_CASE(AfterStop)
44 {
45     BOOST_CHECK_EQUAL(counter, 2);
46     AsyncPoolST::stop();
47     std::this_thread::sleep_for(std::chrono::milliseconds(500));
48     BOOST_CHECK_EQUAL(counter, 2);
49     AsyncPoolST::enqueue([](){ ++counter; });
50     std::this_thread::sleep_for(std::chrono::milliseconds(500));
51     BOOST_CHECK_EQUAL(counter, 2);
52 }
53
54 BOOST_AUTO_TEST_SUITE_END()