| 1098 | } |
| 1099 | |
| 1100 | void CancelDuringCallMethodSelective( |
| 1101 | bool single_server, bool async, bool short_connection) { |
| 1102 | std::cout << " *** single=" << single_server |
| 1103 | << " async=" << async |
| 1104 | << " short=" << short_connection << std::endl; |
| 1105 | |
| 1106 | ASSERT_EQ(0, StartAccept(_ep)); |
| 1107 | |
| 1108 | const size_t NCHANS = 8; |
| 1109 | brpc::SelectiveChannel channel; |
| 1110 | ASSERT_EQ(0, channel.Init("rr", NULL)); |
| 1111 | for (size_t i = 0; i < NCHANS; ++i) { |
| 1112 | brpc::Channel* subchan = new brpc::Channel; |
| 1113 | SetUpChannel(subchan, single_server, short_connection); |
| 1114 | ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; |
| 1115 | } |
| 1116 | |
| 1117 | brpc::Controller cntl; |
| 1118 | test::EchoRequest req; |
| 1119 | test::EchoResponse res; |
| 1120 | req.set_message(__FUNCTION__); |
| 1121 | const brpc::CallId cid = cntl.call_id(); |
| 1122 | ASSERT_TRUE(cid.value != 0); |
| 1123 | pthread_t th; |
| 1124 | CancelerArg carg = { 10000, cid }; |
| 1125 | ASSERT_EQ(0, pthread_create(&th, NULL, Canceler, &carg)); |
| 1126 | req.set_sleep_us(carg.sleep_before_cancel_us * 2); |
| 1127 | butil::Timer tm; |
| 1128 | tm.start(); |
| 1129 | CallMethod(&channel, &cntl, &req, &res, async); |
| 1130 | tm.stop(); |
| 1131 | EXPECT_LT(labs(tm.u_elapsed() - carg.sleep_before_cancel_us), 10000); |
| 1132 | ASSERT_EQ(0, pthread_join(th, NULL)); |
| 1133 | EXPECT_EQ(ECANCELED, cntl.ErrorCode()); |
| 1134 | EXPECT_EQ(1, cntl.sub_count()); |
| 1135 | EXPECT_EQ(ECANCELED, cntl.sub(0)->ErrorCode()); |
| 1136 | StopAndJoin(); |
| 1137 | } |
| 1138 | |
| 1139 | void CancelAfterCallMethod( |
| 1140 | bool single_server, bool async, bool short_connection) { |