15 TEST(recurrent_shared_future, use_case) {
16 using namespace carla;
20 constexpr
size_t number_of_threads = 12u;
21 constexpr
size_t number_of_openings = 40u;
23 std::atomic_size_t count{0u};
24 std::atomic_bool done{
false};
28 auto result = future.
WaitFor(1s);
29 ASSERT_TRUE(result.has_value());
30 ASSERT_EQ(*result, 42);
35 std::this_thread::sleep_for(100ms);
36 for (
auto i = 0u; i < number_of_openings - 1u; ++i) {
38 std::this_thread::sleep_for(10ms);
43 ASSERT_EQ(count, number_of_openings * number_of_threads);
46 TEST(recurrent_shared_future, timeout) {
47 using namespace carla;
49 auto result = future.
WaitFor(1ns);
50 ASSERT_FALSE(result.has_value());
53 TEST(recurrent_shared_future, exception) {
54 using namespace carla;
57 const std::string message =
"Uh oh an exception!";
60 std::this_thread::sleep_for(10ms);
66 }
catch (
const std::exception &e) {
67 ASSERT_STREQ(e.what(), message.c_str());
void SetValue(const T2 &value)
Set the value and notify all waiting threads.
void CreateThread(F &&functor)
void SetException(ExceptionT &&exception)
Set a exception, this exception will be thrown on all the threads waiting.
This file contains definitions of common data structures used in traffic manager. ...
TEST(recurrent_shared_future, use_case)
This class is meant to be used similar to a shared future, but the value can be set any number of tim...
void CreateThreads(size_t count, F functor)
boost::optional< T > WaitFor(time_duration timeout)
Wait until the next value is set.