| 1440 | } |
| 1441 | |
| 1442 | void TestBackupRequestSelective( |
| 1443 | bool single_server, bool async, bool short_connection) { |
| 1444 | std::cout << " *** single=" << single_server |
| 1445 | << " async=" << async |
| 1446 | << " short=" << short_connection << std::endl; |
| 1447 | ASSERT_EQ(0, StartAccept(_ep)); |
| 1448 | |
| 1449 | const size_t NCHANS = 8; |
| 1450 | brpc::SelectiveChannel channel; |
| 1451 | ASSERT_EQ(0, channel.Init("rr", NULL)); |
| 1452 | for (size_t i = 0; i < NCHANS; ++i) { |
| 1453 | brpc::Channel* subchan = new brpc::Channel; |
| 1454 | SetUpChannel(subchan, single_server, short_connection); |
| 1455 | ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; |
| 1456 | } |
| 1457 | |
| 1458 | brpc::Controller cntl; |
| 1459 | test::EchoRequest req; |
| 1460 | test::EchoResponse res; |
| 1461 | req.set_message(__FUNCTION__); |
| 1462 | cntl.set_backup_request_ms(20); |
| 1463 | cntl.set_timeout_ms(100); |
| 1464 | std::atomic<int> call_cnt(0); |
| 1465 | _svc.SetMockFunc([&call_cnt](google::protobuf::RpcController* cntl_base, |
| 1466 | const ::test::EchoRequest*, |
| 1467 | ::test::EchoResponse*, |
| 1468 | google::protobuf::Closure*) { |
| 1469 | brpc::Controller* cntl = static_cast<brpc::Controller*>(cntl_base); |
| 1470 | int see_cnt = call_cnt.fetch_add(1, std::memory_order_relaxed); |
| 1471 | if (see_cnt == 0) { |
| 1472 | LOG(INFO) << "slow node"; |
| 1473 | bthread_usleep(30 * 1000); |
| 1474 | } else { |
| 1475 | LOG(INFO) << "normal node "; |
| 1476 | butil::IOBuf iobuf; |
| 1477 | iobuf.append("123"); |
| 1478 | cntl->response_attachment().swap(iobuf); |
| 1479 | } |
| 1480 | }); |
| 1481 | butil::Timer tm; |
| 1482 | tm.start(); |
| 1483 | CallMethod(&channel, &cntl, &req, &res, async); |
| 1484 | tm.stop(); |
| 1485 | EXPECT_FALSE(cntl.Failed()); |
| 1486 | EXPECT_EQ(call_cnt.load(std::memory_order_relaxed), 2); |
| 1487 | EXPECT_EQ(cntl.response_attachment().to_string(), "123"); |
| 1488 | StopAndJoin(); |
| 1489 | } |
| 1490 | |
| 1491 | void TestBackupRequestSelectiveResponseRace() { |
| 1492 | ASSERT_EQ(0, StartAccept(_ep)); |
nothing calls this directly
no test coverage detected