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

Method TestSuccessParallel2

test/brpc_channel_unittest.cpp:810–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

808 }
809
810 void TestSuccessParallel2(bool single_server, bool async, bool short_connection) {
811 std::cout << " *** single=" << single_server
812 << " async=" << async
813 << " short=" << short_connection << std::endl;
814
815 ASSERT_EQ(0, StartAccept(_ep));
816 const size_t NCHANS = 8;
817 brpc::Channel subchans[NCHANS];
818 brpc::ParallelChannel channel;
819 for (size_t i = 0; i < NCHANS; ++i) {
820 SetUpChannel(&subchans[i], single_server, short_connection);
821 ASSERT_EQ(0, channel.AddChannel(
822 &subchans[i], brpc::DOESNT_OWN_CHANNEL,
823 new GetReqAndAddRes, new MergeNothing));
824 }
825 brpc::Controller cntl;
826 test::ComboRequest req;
827 test::ComboResponse res;
828 CallMethod(&channel, &cntl, &req, &res, false);
829 ASSERT_TRUE(cntl.Failed()); // req does not have .requests
830 ASSERT_EQ(brpc::EREQUEST, cntl.ErrorCode());
831
832 for (size_t i = 0; i < NCHANS; ++i) {
833 ::test::EchoRequest* sub_req = req.add_requests();
834 sub_req->set_message(butil::string_printf("hello_%llu", (long long)i));
835 sub_req->set_code(i + 1);
836 }
837
838 // non-parallel channel does not work.
839 cntl.Reset();
840 CallMethod(&subchans[0], &cntl, &req, &res, false);
841 ASSERT_TRUE(cntl.Failed());
842 ASSERT_EQ(brpc::EINTERNAL, cntl.ErrorCode()) << cntl.ErrorText();
843 ASSERT_TRUE(butil::StringPiece(cntl.ErrorText()).ends_with("Method ComboEcho() not implemented."));
844
845 // do the rpc call.
846 cntl.Reset();
847 CallMethod(&channel, &cntl, &req, &res, async);
848
849 EXPECT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText();
850 ASSERT_GT(cntl.latency_us(), 0);
851 ASSERT_EQ((int)NCHANS, res.responses_size());
852 for (int i = 0; i < res.responses_size(); ++i) {
853 EXPECT_EQ(butil::string_printf("received hello_%d", i),
854 res.responses(i).message());
855 ASSERT_EQ(1, res.responses(i).code_list_size());
856 EXPECT_EQ(i + 1, res.responses(i).code_list(0));
857 }
858 if (short_connection) {
859 // Sleep to let `_messenger' detect `Socket' being `SetFailed'
860 const int64_t start_time = butil::cpuwide_time_us();
861 while (_messenger.ConnectionCount() != 0) {
862 EXPECT_LT(butil::cpuwide_time_us(), start_time + 100000L/*100ms*/);
863 bthread_usleep(1000);
864 }
865 } else {
866 EXPECT_GE(1ul, _messenger.ConnectionCount());
867 }

Callers

nothing calls this directly

Calls 12

string_printfFunction · 0.85
cpuwide_time_usFunction · 0.85
bthread_usleepFunction · 0.85
ErrorCodeMethod · 0.80
ErrorTextMethod · 0.80
ends_withMethod · 0.80
latency_usMethod · 0.80
ConnectionCountMethod · 0.80
AddChannelMethod · 0.45
FailedMethod · 0.45
ResetMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected