Skip to content

Commit 3227900

Browse files
committed
test: allow mock receiver to return unsplit strings
1 parent e3bffa3 commit 3227900

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tests/testStatsdClient.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {
7984
void 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

Comments
 (0)