MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / mock

Function mock

deps/cpp-statsd-client/tests/testStatsdClient.cpp:12–32  ·  view source on GitHub ↗

Each test suite below spawns a thread to recv the client messages over UDP as if it were a real statsd server Note that we could just synchronously recv metrics and not use a thread but doing the test async has the advantage that we can test the threaded batching mode in a straightforward way. The server thread basically just keeps storing metrics in an vector until it hears a special one signalin

Source from the content-addressed store, hash-verified

10// advantage that we can test the threaded batching mode in a straightforward way. The server thread basically
11// just keeps storing metrics in an vector until it hears a special one signaling the test is over and bails
12void mock(StatsdServer& server, std::vector<std::string>& messages) {
13 do {
14 // Grab the messages that are waiting
15 auto recvd = server.receive();
16
17 // Split the messages on '\n'
18 auto start = std::string::npos;
19 do {
20 // Keep this message
21 auto end = recvd.find('\n', ++start);
22 messages.emplace_back(recvd.substr(start, end));
23 start = end;
24
25 // Bail if we found the special quit message
26 if (messages.back().find("DONE") != std::string::npos) {
27 messages.pop_back();
28 return;
29 }
30 } while (start != std::string::npos);
31 } while (server.errorMessage().empty() && !messages.back().empty());
32}
33
34template <typename SocketWrapper>
35void throwOnError(const SocketWrapper& wrapped, bool expectEmpty = true, const std::string& extraMessage = "") {

Callers

nothing calls this directly

Calls 3

receiveMethod · 0.80
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected