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

Method TestRetryBackoff

test/brpc_channel_unittest.cpp:2066–2116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2064 }
2065
2066 void TestRetryBackoff(bool async, bool short_connection, bool fixed_backoff,
2067 bool retry_backoff_in_pthread) {
2068 ASSERT_EQ(0, StartAccept(_ep));
2069
2070 const int32_t backoff_time_ms = 100;
2071 const int32_t no_backoff_remaining_rpc_time_ms = 100;
2072 std::unique_ptr<brpc::RetryPolicy> retry_ptr;
2073 if (fixed_backoff) {
2074 retry_ptr.reset(
2075 new brpc::RpcRetryPolicyWithFixedBackoff(backoff_time_ms,
2076 no_backoff_remaining_rpc_time_ms,
2077 retry_backoff_in_pthread));
2078 } else {
2079 retry_ptr.reset(
2080 new brpc::RpcRetryPolicyWithJitteredBackoff(backoff_time_ms,
2081 backoff_time_ms + 20,
2082 no_backoff_remaining_rpc_time_ms,
2083 retry_backoff_in_pthread));
2084 }
2085
2086 brpc::Channel channel;
2087 brpc::ChannelOptions opt;
2088 opt.timeout_ms = 1000;
2089 opt.retry_policy = retry_ptr.get();
2090 if (short_connection) {
2091 opt.connection_type = brpc::CONNECTION_TYPE_SHORT;
2092 }
2093 butil::TempFile server_list;
2094 EXPECT_EQ(0, server_list.save_format(
2095 "127.0.0.1:100\n"
2096 "127.0.0.1:200\n"
2097 "%s", endpoint2str(_ep).c_str()));
2098 std::string naming_url = std::string("fIle://")
2099 + server_list.fname();
2100 EXPECT_EQ(0, channel.Init(naming_url.c_str(), "RR", &opt));
2101
2102 const int RETRY_NUM = 3;
2103 test::EchoRequest req;
2104 test::EchoResponse res;
2105 brpc::Controller cntl;
2106 req.set_message(__FUNCTION__);
2107 cntl.set_max_retry(RETRY_NUM);
2108 CallMethod(&channel, &cntl, &req, &res, async);
2109 if (cntl.retried_count() > 0) {
2110 EXPECT_GT(cntl.latency_us(), ((int64_t)backoff_time_ms * 1000) * cntl.retried_count())
2111 << "latency_us=" << cntl.latency_us() << " retried_count=" << cntl.retried_count()
2112 << " enable_retry_backoff_in_pthread=" << retry_backoff_in_pthread;
2113 }
2114 EXPECT_EQ(0, cntl.ErrorCode()) << async << ", " << short_connection;
2115 StopAndJoin();
2116 }
2117
2118 void TestBackupRequest(bool single_server, bool async,
2119 bool short_connection) {

Callers 1

Calls 11

endpoint2strFunction · 0.85
save_formatMethod · 0.80
fnameMethod · 0.80
set_max_retryMethod · 0.80
retried_countMethod · 0.80
latency_usMethod · 0.80
ErrorCodeMethod · 0.80
resetMethod · 0.45
getMethod · 0.45
c_strMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected