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

Method TestSuccessDuplicatedParallel

test/brpc_channel_unittest.cpp:665–715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

663 }
664
665 void TestSuccessDuplicatedParallel(
666 bool single_server, bool async, bool short_connection) {
667 std::cout << " *** single=" << single_server
668 << " async=" << async
669 << " short=" << short_connection << std::endl;
670
671 ASSERT_EQ(0, StartAccept(_ep));
672 const size_t NCHANS = 8;
673 brpc::Channel* subchan = new DeleteOnlyOnceChannel;
674 SetUpChannel(subchan, single_server, short_connection);
675 brpc::ParallelChannel channel;
676 // Share the CallMapper and ResponseMerger should be fine because
677 // they're intrusively shared.
678 SetCode* set_code = new SetCode;
679 for (size_t i = 0; i < NCHANS; ++i) {
680 ASSERT_EQ(0, channel.AddChannel(
681 subchan,
682 // subchan should be deleted (for only once)
683 ((i % 2) ? brpc::DOESNT_OWN_CHANNEL : brpc::OWNS_CHANNEL),
684 set_code, NULL));
685 }
686 ASSERT_EQ((int)NCHANS, set_code->ref_count());
687 brpc::Controller cntl;
688 test::EchoRequest req;
689 test::EchoResponse res;
690 req.set_message(__FUNCTION__);
691 req.set_code(23);
692 CallMethod(&channel, &cntl, &req, &res, async);
693
694 EXPECT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText();
695 EXPECT_EQ(NCHANS, (size_t)cntl.sub_count());
696 for (int i = 0; i < cntl.sub_count(); ++i) {
697 EXPECT_TRUE(cntl.sub(i) && !cntl.sub(i)->Failed()) << "i=" << i;
698 }
699 EXPECT_EQ("received " + std::string(__FUNCTION__), res.message());
700 ASSERT_EQ(NCHANS, (size_t)res.code_list_size());
701 for (size_t i = 0; i < NCHANS; ++i) {
702 ASSERT_EQ((int)i+1, res.code_list(i));
703 }
704 if (short_connection) {
705 // Sleep to let `_messenger' detect `Socket' being `SetFailed'
706 const int64_t start_time = butil::cpuwide_time_us();
707 while (_messenger.ConnectionCount() != 0) {
708 EXPECT_LT(butil::cpuwide_time_us(), start_time + 100000L/*100ms*/);
709 bthread_usleep(1000);
710 }
711 } else {
712 EXPECT_GE(1ul, _messenger.ConnectionCount());
713 }
714 StopAndJoin();
715 }
716
717 void TestSuccessSelective(bool single_server, bool async, bool short_connection) {
718 std::cout << " *** single=" << single_server

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
AddChannelMethod · 0.45
ref_countMethod · 0.45
FailedMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected