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

Method TestSuccessLimitParallel

test/brpc_channel_unittest.cpp:871–922  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

869 }
870
871 void TestSuccessLimitParallel(bool single_server, bool async, bool short_connection) {
872 std::cout << " *** single=" << single_server
873 << " async=" << async
874 << " short=" << short_connection << std::endl;
875
876 ASSERT_EQ(0, StartAccept(_ep));
877 const size_t NCHANS = 8;
878 brpc::Channel subchans[NCHANS];
879 brpc::ParallelChannel channel;
880 brpc::ParallelChannelOptions options;
881 // Only care about the first successful response.
882 options.success_limit = 1;
883 channel.Init(&options);
884 butil::intrusive_ptr<brpc::CallMapper> fast_call_mapper(new SuccessLimitCallMapper);
885 for (size_t i = 0; i < NCHANS; ++i) {
886 SetUpChannel(&subchans[i], single_server, short_connection);
887 ASSERT_EQ(0, channel.AddChannel(
888 &subchans[i], brpc::DOESNT_OWN_CHANNEL, fast_call_mapper, NULL));
889 }
890 brpc::Controller cntl;
891 test::EchoRequest req;
892 test::EchoResponse res;
893 req.set_message(__FUNCTION__);
894 req.set_code(23);
895 CallMethod(&channel, &cntl, &req, &res, async);
896
897 EXPECT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText();
898 EXPECT_EQ(NCHANS, (size_t)cntl.sub_count());
899 for (int i = 0; i < cntl.sub_count(); ++i) {
900 EXPECT_TRUE(cntl.sub(i)) << "i=" << i;
901 if (0 == i) {
902 EXPECT_TRUE(!cntl.sub(i)->Failed()) << "i=" << i;
903 } else {
904 EXPECT_TRUE(cntl.sub(i)->Failed()) << "i=" << i;
905 EXPECT_EQ(brpc::EPCHANFINISH, cntl.sub(i)->ErrorCode()) << "i=" << i;
906 }
907 }
908 EXPECT_EQ("received " + std::string(__FUNCTION__), res.message());
909 ASSERT_EQ(1, res.code_list_size());
910 ASSERT_EQ((int)1, res.code_list(0));
911 if (short_connection) {
912 // Sleep to let `_messenger' detect `Socket' being `SetFailed'
913 const int64_t start_time = butil::cpuwide_time_us();
914 while (_messenger.ConnectionCount() != 0) {
915 EXPECT_LT(butil::cpuwide_time_us(), start_time + 100000L/*100ms*/);
916 bthread_usleep(1000);
917 }
918 } else {
919 EXPECT_GE(1ul, _messenger.ConnectionCount());
920 }
921 StopAndJoin();
922 }
923
924 struct CancelerArg {
925 int64_t sleep_before_cancel_us;

Callers

nothing calls this directly

Calls 11

cpuwide_time_usFunction · 0.85
bthread_usleepFunction · 0.85
ErrorCodeMethod · 0.80
ErrorTextMethod · 0.80
sub_countMethod · 0.80
subMethod · 0.80
ConnectionCountMethod · 0.80
InitMethod · 0.45
AddChannelMethod · 0.45
FailedMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected