| 12 | using namespace std::chrono_literals; |
| 13 | |
| 14 | TEST(recurrent_shared_future, use_case) { |
| 15 | using namespace carla; |
| 16 | ThreadGroup threads; |
| 17 | RecurrentSharedFuture<int> future; |
| 18 | |
| 19 | constexpr size_t number_of_threads = 12u; |
| 20 | constexpr size_t number_of_openings = 40u; |
| 21 | |
| 22 | std::atomic_size_t count{0u}; |
| 23 | std::atomic_bool done{false}; |
| 24 | |
| 25 | threads.CreateThreads(number_of_threads, [&]() { |
| 26 | while (!done) { |
| 27 | auto result = future.WaitFor(1s); |
| 28 | ASSERT_TRUE(result.has_value()); |
| 29 | ASSERT_EQ(*result, 42); |
| 30 | ++count; |
| 31 | } |
| 32 | }); |
| 33 | |
| 34 | std::this_thread::sleep_for(100ms); |
| 35 | for (auto i = 0u; i < number_of_openings - 1u; ++i) { |
| 36 | future.SetValue(42); |
| 37 | std::this_thread::sleep_for(10ms); |
| 38 | } |
| 39 | done = true; |
| 40 | future.SetValue(42); |
| 41 | threads.JoinAll(); |
| 42 | ASSERT_EQ(count, number_of_openings * number_of_threads); |
| 43 | } |
| 44 | |
| 45 | TEST(recurrent_shared_future, timeout) { |
| 46 | using namespace carla; |
nothing calls this directly
no test coverage detected