| 88 | }; |
| 89 | |
| 90 | TEST_F(EspTest, complete_flow) { |
| 91 | brpc::EspMessage req; |
| 92 | brpc::EspMessage res; |
| 93 | |
| 94 | req.head.to.stub = STUB; |
| 95 | req.head.msg = MSG; |
| 96 | req.head.msg_id = MSG_ID; |
| 97 | req.body.append(EXP_REQUEST); |
| 98 | |
| 99 | butil::IOBuf req_buf; |
| 100 | brpc::Controller cntl; |
| 101 | cntl._response = &res; |
| 102 | ASSERT_EQ(0, brpc::Socket::Address(_socket->id(), &cntl._current_call.sending_sock)); |
| 103 | |
| 104 | brpc::policy::SerializeEspRequest(&req_buf, &cntl, &req); |
| 105 | ASSERT_FALSE(cntl.Failed()); |
| 106 | ASSERT_EQ(sizeof(req.head) + req.body.size(), req_buf.size()); |
| 107 | |
| 108 | const brpc::Authenticator* auth = brpc::policy::global_esp_authenticator(); |
| 109 | butil::IOBuf packet_buf; |
| 110 | brpc::policy::PackEspRequest(&packet_buf, NULL, cntl.call_id().value, NULL, &cntl, req_buf, auth); |
| 111 | |
| 112 | std::string auth_str; |
| 113 | auth->GenerateCredential(&auth_str); |
| 114 | |
| 115 | ASSERT_FALSE(cntl.Failed()); |
| 116 | ASSERT_EQ(req_buf.size() + auth_str.size(), packet_buf.size()); |
| 117 | |
| 118 | WriteResponse(cntl, MSG); |
| 119 | |
| 120 | butil::IOPortal response_buf; |
| 121 | response_buf.append_from_file_descriptor(_pipe_fds[0], 1024); |
| 122 | |
| 123 | brpc::ParseResult res_pr = |
| 124 | brpc::policy::ParseEspMessage(&response_buf, NULL, false, NULL); |
| 125 | ASSERT_EQ(brpc::PARSE_OK, res_pr.error()); |
| 126 | |
| 127 | brpc::InputMessageBase* res_msg = res_pr.message(); |
| 128 | _socket->ReAddress(&res_msg->_socket); |
| 129 | |
| 130 | brpc::policy::ProcessEspResponse(res_msg); |
| 131 | |
| 132 | ASSERT_FALSE(cntl.Failed()); |
| 133 | ASSERT_EQ(EXP_RESPONSE, res.body.to_string()); |
| 134 | } |
| 135 | |
| 136 | TEST_F(EspTest, wrong_response_head) { |
| 137 | brpc::EspMessage res; |
nothing calls this directly
no test coverage detected