| 1055 | } |
| 1056 | |
| 1057 | void CancelDuringCallMethodParallel( |
| 1058 | bool single_server, bool async, bool short_connection) { |
| 1059 | std::cout << " *** single=" << single_server |
| 1060 | << " async=" << async |
| 1061 | << " short=" << short_connection << std::endl; |
| 1062 | |
| 1063 | ASSERT_EQ(0, StartAccept(_ep)); |
| 1064 | |
| 1065 | const size_t NCHANS = 8; |
| 1066 | brpc::Channel subchans[NCHANS]; |
| 1067 | brpc::ParallelChannel channel; |
| 1068 | for (size_t i = 0; i < NCHANS; ++i) { |
| 1069 | SetUpChannel(&subchans[i], single_server, short_connection); |
| 1070 | ASSERT_EQ(0, channel.AddChannel( |
| 1071 | &subchans[i], brpc::DOESNT_OWN_CHANNEL, |
| 1072 | NULL, NULL)); |
| 1073 | } |
| 1074 | |
| 1075 | brpc::Controller cntl; |
| 1076 | test::EchoRequest req; |
| 1077 | test::EchoResponse res; |
| 1078 | req.set_message(__FUNCTION__); |
| 1079 | const brpc::CallId cid = cntl.call_id(); |
| 1080 | ASSERT_TRUE(cid.value != 0); |
| 1081 | pthread_t th; |
| 1082 | CancelerArg carg = { 10000, cid }; |
| 1083 | ASSERT_EQ(0, pthread_create(&th, NULL, Canceler, &carg)); |
| 1084 | req.set_sleep_us(carg.sleep_before_cancel_us * 2); |
| 1085 | butil::Timer tm; |
| 1086 | tm.start(); |
| 1087 | CallMethod(&channel, &cntl, &req, &res, async); |
| 1088 | tm.stop(); |
| 1089 | EXPECT_LT(labs(tm.u_elapsed() - carg.sleep_before_cancel_us), 10000); |
| 1090 | ASSERT_EQ(0, pthread_join(th, NULL)); |
| 1091 | EXPECT_EQ(ECANCELED, cntl.ErrorCode()); |
| 1092 | EXPECT_EQ(NCHANS, (size_t)cntl.sub_count()); |
| 1093 | for (int i = 0; i < cntl.sub_count(); ++i) { |
| 1094 | EXPECT_EQ(ECANCELED, cntl.sub(i)->ErrorCode()) << "i=" << i; |
| 1095 | } |
| 1096 | EXPECT_LT(labs(cntl.latency_us() - carg.sleep_before_cancel_us), 10000); |
| 1097 | StopAndJoin(); |
| 1098 | } |
| 1099 | |
| 1100 | void CancelDuringCallMethodSelective( |
| 1101 | bool single_server, bool async, bool short_connection) { |
nothing calls this directly
no test coverage detected