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

Method TestSuccess

test/brpc_channel_unittest.cpp:469–544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467 }
468
469 void TestSuccess(bool single_server, bool async, bool short_connection) {
470 std::cout << " *** single=" << single_server
471 << " async=" << async
472 << " short=" << short_connection << std::endl;
473
474 ASSERT_EQ(0, StartAccept(_ep));
475 brpc::Channel channel;
476 SetUpChannel(&channel, single_server, short_connection);
477
478 brpc::Controller cntl;
479 test::EchoRequest req;
480 test::EchoResponse res;
481 req.set_message(__FUNCTION__);
482 CallMethod(&channel, &cntl, &req, &res, async);
483
484 EXPECT_EQ(0, cntl.ErrorCode())
485 << single_server << ", " << async << ", " << short_connection;
486 const uint64_t receiving_socket_id = res.receiving_socket_id();
487 EXPECT_EQ(0, cntl.sub_count());
488 EXPECT_TRUE(NULL == cntl.sub(-1));
489 EXPECT_TRUE(NULL == cntl.sub(0));
490 EXPECT_TRUE(NULL == cntl.sub(1));
491 EXPECT_EQ("received " + std::string(__FUNCTION__), res.message());
492 if (short_connection) {
493 // Sleep to let `_messenger' detect `Socket' being `SetFailed'
494 const int64_t start_time = butil::cpuwide_time_us();
495 while (_messenger.ConnectionCount() != 0) {
496 EXPECT_LT(butil::cpuwide_time_us(), start_time + 100000L/*100ms*/);
497 bthread_usleep(1000);
498 }
499 } else {
500 EXPECT_GE(1ul, _messenger.ConnectionCount());
501 }
502 if (single_server && !short_connection) {
503 // Reuse the connection
504 brpc::Channel channel2;
505 SetUpChannel(&channel2, single_server, short_connection);
506 cntl.Reset();
507 req.Clear();
508 res.Clear();
509 req.set_message(__FUNCTION__);
510 CallMethod(&channel2, &cntl, &req, &res, async);
511 EXPECT_EQ(0, cntl.ErrorCode())
512 << single_server << ", " << async << ", " << short_connection;
513 EXPECT_EQ(receiving_socket_id, res.receiving_socket_id());
514
515 // A different connection_group does not reuse the connection
516 brpc::Channel channel3;
517 SetUpChannel(&channel3, single_server, short_connection,
518 NULL, "another_group");
519 cntl.Reset();
520 req.Clear();
521 res.Clear();
522 req.set_message(__FUNCTION__);
523 CallMethod(&channel3, &cntl, &req, &res, async);
524 EXPECT_EQ(0, cntl.ErrorCode())
525 << single_server << ", " << async << ", " << short_connection;
526 const uint64_t receiving_socket_id2 = res.receiving_socket_id();

Callers

nothing calls this directly

Calls 9

cpuwide_time_usFunction · 0.85
bthread_usleepFunction · 0.85
ErrorCodeMethod · 0.80
sub_countMethod · 0.80
subMethod · 0.80
ConnectionCountMethod · 0.80
messageMethod · 0.45
ResetMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected