MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / TEST

Function TEST

LibCarla/source/test/client/test_recurrent_shared_future.cpp:14–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12using namespace std::chrono_literals;
13
14TEST(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
45TEST(recurrent_shared_future, timeout) {
46 using namespace carla;

Callers

nothing calls this directly

Calls 7

CreateThreadsMethod · 0.80
WaitForMethod · 0.80
SetValueMethod · 0.80
JoinAllMethod · 0.80
CreateThreadMethod · 0.80
SetExceptionMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected