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

Method TestBackupRequestPolicy

test/brpc_channel_unittest.cpp:2174–2217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2172 };
2173
2174 void TestBackupRequestPolicy(bool single_server, bool async,
2175 bool short_connection) {
2176 ASSERT_EQ(0, StartAccept(_ep));
2177 for (int i = 0; i < 2; ++i) {
2178 bool backup = i == 0;
2179 std::cout << " *** single=" << single_server
2180 << " async=" << async
2181 << " short=" << short_connection
2182 << " backup=" << backup
2183 << std::endl;
2184
2185 brpc::Channel channel;
2186 SetUpChannel(&channel, single_server, short_connection, NULL, "", true);
2187
2188 const int RETRY_NUM = 1;
2189 test::EchoRequest req;
2190 test::EchoResponse res;
2191 brpc::Controller cntl;
2192 req.set_message(__FUNCTION__);
2193
2194 _backup_request_policy.backup = backup;
2195 cntl.set_max_retry(RETRY_NUM);
2196 cntl.set_timeout_ms(100); // 100ms
2197 req.set_sleep_us(50000); // 50ms
2198 CallMethod(&channel, &cntl, &req, &res, async);
2199 ASSERT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText();
2200 ASSERT_EQ(backup, cntl.has_backup_request());
2201 ASSERT_EQ(backup ? RETRY_NUM : 0, cntl.retried_count());
2202 bthread_usleep(70000); // wait for the sleep task to finish
2203
2204 if (short_connection) {
2205 // Sleep to let `_messenger' detect `Socket' being `SetFailed'
2206 const int64_t start_time = butil::cpuwide_time_us();
2207 while (_messenger.ConnectionCount() != 0) {
2208 ASSERT_LT(butil::cpuwide_time_us(), start_time + 100000L/*100ms*/);
2209 bthread_usleep(1000);
2210 }
2211 } else {
2212 ASSERT_GE(1ul, _messenger.ConnectionCount());
2213 }
2214 }
2215
2216 StopAndJoin();
2217 }
2218
2219 butil::EndPoint _ep;
2220 butil::TempFile _server_list;

Callers

nothing calls this directly

Calls 9

bthread_usleepFunction · 0.85
cpuwide_time_usFunction · 0.85
set_max_retryMethod · 0.80
set_timeout_msMethod · 0.80
ErrorCodeMethod · 0.80
ErrorTextMethod · 0.80
has_backup_requestMethod · 0.80
retried_countMethod · 0.80
ConnectionCountMethod · 0.80

Tested by

no test coverage detected