| 43 | }; |
| 44 | |
| 45 | TEST(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 | |
| 80 | TEST(streaming, low_level_unsubscribing) { |
| 81 | using namespace util::buffer; |
nothing calls this directly
no test coverage detected