| 1761 | } |
| 1762 | |
| 1763 | void TestDestroyChannelSelective(bool single_server, bool short_connection) { |
| 1764 | std::cout << "*** single=" << single_server |
| 1765 | << ", short=" << short_connection << std::endl; |
| 1766 | |
| 1767 | const size_t NCHANS = 5; |
| 1768 | ASSERT_EQ(0, StartAccept(_ep)); |
| 1769 | brpc::SelectiveChannel* channel = new brpc::SelectiveChannel; |
| 1770 | ASSERT_EQ(0, channel->Init("rr", NULL)); |
| 1771 | for (size_t i = 0; i < NCHANS; ++i) { |
| 1772 | brpc::Channel* subchan = new brpc::Channel(); |
| 1773 | SetUpChannel(subchan, single_server, short_connection); |
| 1774 | ASSERT_EQ(0, channel->AddChannel(subchan, NULL)); |
| 1775 | } |
| 1776 | |
| 1777 | brpc::Controller cntl; |
| 1778 | test::EchoRequest req; |
| 1779 | test::EchoResponse res; |
| 1780 | req.set_sleep_us(10000); |
| 1781 | req.set_message(__FUNCTION__); |
| 1782 | CallMethod(channel, &cntl, &req, &res, true, true/*destroy*/); |
| 1783 | |
| 1784 | EXPECT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText(); |
| 1785 | EXPECT_EQ("received " + std::string(__FUNCTION__), res.message()); |
| 1786 | ASSERT_EQ(_ep, cntl.remote_side()); |
| 1787 | ASSERT_EQ(1, cntl.sub_count()); |
| 1788 | ASSERT_EQ(0, cntl.sub(0)->ErrorCode()); |
| 1789 | |
| 1790 | // Sleep to let `_messenger' detect `Socket' being `SetFailed' |
| 1791 | const int64_t start_time = butil::cpuwide_time_us(); |
| 1792 | while (_messenger.ConnectionCount() != 0) { |
| 1793 | EXPECT_LT(butil::cpuwide_time_us(), start_time + 100000L/*100ms*/); |
| 1794 | bthread_usleep(1000); |
| 1795 | } |
| 1796 | StopAndJoin(); |
| 1797 | } |
| 1798 | |
| 1799 | void RPCThread(brpc::ChannelBase* channel, bool async) { |
| 1800 | brpc::Controller cntl; |
nothing calls this directly
no test coverage detected