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

Function testSendRecv

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

Source from the content-addressed store, hash-verified

77}
78
79void testSendRecv(uint64_t batchSize, uint64_t sendInterval) {
80 StatsdServer mock_server;
81 std::vector<std::string> messages, expected;
82 std::thread server(mock, std::ref(mock_server), std::ref(messages));
83
84 // Set a new config that has the client send messages to a proper address that can be resolved
85 StatsdClient client("localhost", 8125, "sendRecv.", batchSize, sendInterval, 3);
86 throwOnError(client);
87
88 // TODO: I forget if we need to wait for the server to be ready here before sending the first stats
89 // is there a race condition where the client sending before the server binds would drop that clients message
90
91 for (int i = 0; i < 3; ++i) {
92 // Increment "coco"
93 client.increment("coco");
94 throwOnError(client);
95 expected.emplace_back("sendRecv.coco:1|c");
96
97 // Decrement "kiki"
98 client.decrement("kiki");
99 throwOnError(client);
100 expected.emplace_back("sendRecv.kiki:-1|c");
101
102 // Adjusts "toto" by +2
103 client.seed(19); // this seed gets a hit on the first call
104 client.count("toto", 2, 0.1f);
105 throwOnError(client);
106 expected.emplace_back("sendRecv.toto:2|c|@0.10");
107
108 // Gets "sampled out" by the random number generator
109 client.count("popo", 9, 0.1f);
110 throwOnError(client);
111
112 // Record a gauge "titi" to 3
113 client.gauge("titi", 3);
114 throwOnError(client);
115 expected.emplace_back("sendRecv.titi:3|g");
116
117 // Record a gauge "titifloat" to -123.456789 with precision 3
118 client.gauge("titifloat", -123.456789);
119 throwOnError(client);
120 expected.emplace_back("sendRecv.titifloat:-123.457|g");
121
122 // Record a timing of 2ms for "myTiming"
123 client.seed(19);
124 client.timing("myTiming", 2, 0.1f);
125 throwOnError(client);
126 expected.emplace_back("sendRecv.myTiming:2|ms|@0.10");
127
128 // Send a set with 1227 total uniques
129 client.set("tutu", 1227, 2.0f);
130 throwOnError(client);
131 expected.emplace_back("sendRecv.tutu:1227|s");
132
133 // Gauge but with tags
134 client.gauge("dr.röstigrabe", 333, 1.f, {"liegt", "im", "weste"});
135 throwOnError(client);
136 expected.emplace_back("sendRecv.dr.röstigrabe:333|g|#liegt,im,weste");

Callers 1

mainFunction · 0.85

Calls 9

throwOnErrorFunction · 0.85
seedMethod · 0.80
incrementMethod · 0.45
decrementMethod · 0.45
countMethod · 0.45
gaugeMethod · 0.45
timingMethod · 0.45
setMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected