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

Method TestRetry

test/brpc_channel_unittest.cpp:1952–2011  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1950 }
1951
1952 void TestRetry(bool single_server, bool async, bool short_connection) {
1953 std::cout << " *** single=" << single_server
1954 << " async=" << async
1955 << " short=" << short_connection << std::endl;
1956
1957 ASSERT_EQ(0, StartAccept(_ep));
1958 brpc::Channel channel;
1959 SetUpChannel(&channel, single_server, short_connection);
1960
1961 const int RETRY_NUM = 3;
1962 test::EchoRequest req;
1963 test::EchoResponse res;
1964 brpc::Controller cntl;
1965 req.set_message(__FUNCTION__);
1966
1967 // No retry when timeout
1968 cntl.set_max_retry(RETRY_NUM);
1969 cntl.set_timeout_ms(10); // 10ms
1970 req.set_sleep_us(70000); // 70ms
1971 CallMethod(&channel, &cntl, &req, &res, async);
1972 EXPECT_EQ(brpc::ERPCTIMEDOUT, cntl.ErrorCode()) << cntl.ErrorText();
1973 EXPECT_EQ(0, cntl.retried_count());
1974 bthread_usleep(100000); // wait for the sleep task to finish
1975
1976 // Retry when connection broken
1977 cntl.Reset();
1978 cntl.set_max_retry(RETRY_NUM);
1979 _close_fd_once = true;
1980 req.set_sleep_us(0);
1981 CallMethod(&channel, &cntl, &req, &res, async);
1982
1983 if (short_connection) {
1984 // Always succeed
1985 EXPECT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText();
1986 EXPECT_EQ(1, cntl.retried_count());
1987
1988 const int64_t start_time = butil::cpuwide_time_us();
1989 while (_messenger.ConnectionCount() != 0) {
1990 EXPECT_LT(butil::cpuwide_time_us(), start_time + 100000L/*100ms*/);
1991 bthread_usleep(1000);
1992 }
1993 } else {
1994 // May fail if health checker can't revive in time
1995 if (cntl.Failed()) {
1996 EXPECT_EQ(EHOSTDOWN, cntl.ErrorCode()) << single_server << ", " << async;
1997 EXPECT_EQ(RETRY_NUM, cntl.retried_count());
1998 } else {
1999 EXPECT_TRUE(cntl.retried_count() > 0);
2000 }
2001 }
2002 StopAndJoin();
2003 bthread_usleep(100000); // wait for stop
2004
2005 // Retry when connection failed
2006 cntl.Reset();
2007 cntl.set_max_retry(RETRY_NUM);
2008 CallMethod(&channel, &cntl, &req, &res, async);
2009 EXPECT_EQ(EHOSTDOWN, cntl.ErrorCode());

Callers

nothing calls this directly

Calls 10

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
retried_countMethod · 0.80
ConnectionCountMethod · 0.80
ResetMethod · 0.45
FailedMethod · 0.45

Tested by

no test coverage detected