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

Function TEST

LibCarla/source/test/common/test_streaming.cpp:45–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43};
44
45TEST(streaming, low_level_sending_strings) {
46 using namespace util::buffer;
47 using namespace carla::streaming;
48 using namespace carla::streaming::detail;
49 using namespace carla::streaming::low_level;
50
51 constexpr auto number_of_messages = 100u;
52 const std::string message_text = "Hello client!";
53
54 std::atomic_size_t message_count{0u};
55
56 io_context_running io;
57
58 Server<tcp::Server> srv(io.service, TESTING_PORT);
59 srv.SetTimeout(1s);
60
61 auto stream = srv.MakeStream();
62
63 Client<tcp::Client> c;
64 c.Subscribe(io.service, stream.token(), [&](auto message) {
65 ++message_count;
66 ASSERT_EQ(message.size(), message_text.size());
67 const std::string msg = as_string(message);
68 ASSERT_EQ(msg, message_text);
69 });
70
71 for (auto i = 0u; i < number_of_messages; ++i) {
72 std::this_thread::sleep_for(2ms);
73 stream << message_text;
74 }
75
76 std::this_thread::sleep_for(2ms);
77 ASSERT_GE(message_count, number_of_messages - 3u);
78}
79
80TEST(streaming, low_level_unsubscribing) {
81 using namespace util::buffer;

Callers

nothing calls this directly

Calls 15

as_stringFunction · 0.85
tokenMethod · 0.80
get_stream_idMethod · 0.80
ConnectMethod · 0.80
CreateThreadsMethod · 0.80
CreateThreadMethod · 0.80
BufferClass · 0.50
SetTimeoutMethod · 0.45
MakeStreamMethod · 0.45
SubscribeMethod · 0.45
sizeMethod · 0.45
UnSubscribeMethod · 0.45

Tested by

no test coverage detected