MCPcopy Create free account
hub / github.com/apache/brpc / TEST_F

Function TEST_F

test/brpc_input_messenger_unittest.cpp:149–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149TEST_F(MessengerTest, dispatch_tasks) {
150 client_stop = false;
151
152 brpc::Acceptor messenger[NEPOLL];
153 pthread_t cth[NCLIENT];
154 ClientMeta* cm[NCLIENT];
155
156 const brpc::InputMessageHandler pairs[] = {
157 { brpc::policy::ParseHuluMessage,
158 EmptyProcessHuluRequest, NULL, NULL, "dummy_hulu" }
159 };
160
161 for (size_t i = 0; i < NEPOLL; ++i) {
162#ifdef USE_UNIX_DOMAIN_SOCKET
163 char buf[64];
164 snprintf(buf, sizeof(buf), "input_messenger.socket%lu", i);
165 int listening_fd = butil::unix_socket_listen(buf);
166#else
167 int listening_fd = tcp_listen(butil::EndPoint(butil::IP_ANY, 7878));
168#endif
169 ASSERT_TRUE(listening_fd > 0);
170 butil::make_non_blocking(listening_fd);
171 ASSERT_EQ(0, messenger[i].AddHandler(pairs[0]));
172 ASSERT_EQ(0, messenger[i].StartAccept(listening_fd, -1, NULL, false));
173 }
174
175 for (size_t i = 0; i < NCLIENT; ++i) {
176 cm[i] = new ClientMeta;
177 cm[i]->times = 0;
178 cm[i]->bytes = 0;
179 ASSERT_EQ(0, pthread_create(&cth[i], NULL, client_thread, cm[i]));
180 }
181
182 sleep(1);
183
184
185 LOG(INFO) << "Begin to profile... (5 seconds)";
186 ProfilerStart("input_messenger.prof");
187
188 size_t start_client_bytes = 0;
189 for (size_t i = 0; i < NCLIENT; ++i) {
190 start_client_bytes += cm[i]->bytes;
191 }
192 butil::Timer tm;
193 tm.start();
194
195 sleep(5);
196
197 tm.stop();
198 ProfilerStop();
199 LOG(INFO) << "End profiling";
200
201 client_stop = true;
202
203 size_t client_bytes = 0;
204 for (size_t i = 0; i < NCLIENT; ++i) {
205 client_bytes += cm[i]->bytes;
206 }

Callers

nothing calls this directly

Calls 13

snprintfFunction · 0.85
unix_socket_listenFunction · 0.85
tcp_listenFunction · 0.85
EndPointClass · 0.85
make_non_blockingFunction · 0.85
ProfilerStartFunction · 0.85
ProfilerStopFunction · 0.85
AddHandlerMethod · 0.80
u_elapsedMethod · 0.80
StopAcceptMethod · 0.80
StartAcceptMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected