@@ -9,17 +9,22 @@ using namespace Statsd;
99// Note that we could just synchronously recv metrics and not use a thread but doing the test async has the
1010// advantage that we can test the threaded batching mode in a straightforward way. The server thread basically
1111// just keeps storing metrics in an vector until it hears a special one signaling the test is over and bails
12- void mock (StatsdServer& server, std::vector<std::string>& messages) {
12+ void mock (StatsdServer& server, std::vector<std::string>& messages, bool split ) {
1313 do {
1414 // Grab the messages that are waiting
1515 auto recvd = server.receive ();
1616
17+ // If we don't want splitting, give the raw message though we still go
18+ // through splitting to parse the quit message
19+ if (!split) messages.emplace_back (recvd);
20+
1721 // Split the messages on '\n'
1822 auto start = std::string::npos;
1923 do {
20- // Keep this message
24+ // Keep this message (unless we don't want splitting, then we
25+ // do nothing because we already stored the whole batch)
2126 auto end = recvd.find (' \n ' , ++start);
22- messages.emplace_back (recvd.substr (start, end));
27+ if (split) messages.emplace_back (recvd.substr (start, end));
2328 start = end;
2429
2530 // Bail if we found the special quit message
@@ -79,7 +84,7 @@ void testReconfigure() {
7984void testSendRecv (uint64_t batchSize, uint64_t sendInterval) {
8085 StatsdServer mock_server;
8186 std::vector<std::string> messages, expected;
82- std::thread server (mock, std::ref (mock_server), std::ref (messages));
87+ std::thread server (mock, std::ref (mock_server), std::ref (messages), /* split= */ true );
8388
8489 // Set a new config that has the client send messages to a proper address that can be resolved
8590 StatsdClient client (" localhost" , 8125 , " sendRecv." , batchSize, sendInterval, 3 );
0 commit comments