| 147 | } |
| 148 | |
| 149 | TEST_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 | } |
nothing calls this directly
no test coverage detected