| 2116 | } |
| 2117 | |
| 2118 | void TestBackupRequest(bool single_server, bool async, |
| 2119 | bool short_connection) { |
| 2120 | std::cout << " *** single=" << single_server |
| 2121 | << " async=" << async |
| 2122 | << " short=" << short_connection << std::endl; |
| 2123 | |
| 2124 | ASSERT_EQ(0, StartAccept(_ep)); |
| 2125 | brpc::Channel channel; |
| 2126 | SetUpChannel(&channel, single_server, short_connection); |
| 2127 | |
| 2128 | const int RETRY_NUM = 1; |
| 2129 | test::EchoRequest req; |
| 2130 | test::EchoResponse res; |
| 2131 | brpc::Controller cntl; |
| 2132 | req.set_message(__FUNCTION__); |
| 2133 | |
| 2134 | cntl.set_max_retry(RETRY_NUM); |
| 2135 | cntl.set_backup_request_ms(10); // 10ms |
| 2136 | cntl.set_timeout_ms(100); // 10ms |
| 2137 | req.set_sleep_us(50000); // 100ms |
| 2138 | CallMethod(&channel, &cntl, &req, &res, async); |
| 2139 | ASSERT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText(); |
| 2140 | ASSERT_TRUE(cntl.has_backup_request()); |
| 2141 | ASSERT_EQ(RETRY_NUM, cntl.retried_count()); |
| 2142 | bthread_usleep(70000); // wait for the sleep task to finish |
| 2143 | |
| 2144 | if (short_connection) { |
| 2145 | // Sleep to let `_messenger' detect `Socket' being `SetFailed' |
| 2146 | const int64_t start_time = butil::cpuwide_time_us(); |
| 2147 | while (_messenger.ConnectionCount() != 0) { |
| 2148 | EXPECT_LT(butil::cpuwide_time_us(), start_time + 100000L/*100ms*/); |
| 2149 | bthread_usleep(1000); |
| 2150 | } |
| 2151 | } else { |
| 2152 | EXPECT_GE(1ul, _messenger.ConnectionCount()); |
| 2153 | } |
| 2154 | StopAndJoin(); |
| 2155 | } |
| 2156 | |
| 2157 | class BackupRequestPolicyImpl : public brpc::BackupRequestPolicy { |
| 2158 | public: |
nothing calls this directly
no test coverage detected