|
|
@ -44,59 +44,6 @@ using ::testing::Expectation; |
|
|
|
using ::testing::NiceMock; |
|
|
|
using ::testing::NiceMock; |
|
|
|
using ::testing::Return; |
|
|
|
using ::testing::Return; |
|
|
|
|
|
|
|
|
|
|
|
std::string MetadataString(const Metadata& a) { |
|
|
|
|
|
|
|
return absl::StrCat( |
|
|
|
|
|
|
|
"{", |
|
|
|
|
|
|
|
absl::StrJoin( |
|
|
|
|
|
|
|
a, ", ", |
|
|
|
|
|
|
|
[](std::string* out, const std::pair<std::string, std::string>& kv) { |
|
|
|
|
|
|
|
out->append( |
|
|
|
|
|
|
|
absl::StrCat("\"", kv.first, "\": \"", kv.second, "\"")); |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
"}"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MetadataEquivalent(Metadata a, Metadata b) { |
|
|
|
|
|
|
|
std::sort(a.begin(), a.end()); |
|
|
|
|
|
|
|
std::sort(b.begin(), b.end()); |
|
|
|
|
|
|
|
return a == b; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Matches with transactions having the desired flag, method_ref,
|
|
|
|
|
|
|
|
// initial_metadata, and message_data.
|
|
|
|
|
|
|
|
MATCHER_P4(TransactionMatches, flag, method_ref, initial_metadata, message_data, |
|
|
|
|
|
|
|
"") { |
|
|
|
|
|
|
|
if (arg->GetFlags() != flag) return false; |
|
|
|
|
|
|
|
if (flag & kFlagPrefix) { |
|
|
|
|
|
|
|
if (arg->GetMethodRef() != method_ref) { |
|
|
|
|
|
|
|
printf("METHOD REF NOT EQ: %s %s\n", |
|
|
|
|
|
|
|
std::string(arg->GetMethodRef()).c_str(), |
|
|
|
|
|
|
|
std::string(method_ref).c_str()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!MetadataEquivalent(arg->GetPrefixMetadata(), initial_metadata)) { |
|
|
|
|
|
|
|
printf("METADATA NOT EQUIVALENT: %s %s\n", |
|
|
|
|
|
|
|
MetadataString(arg->GetPrefixMetadata()).c_str(), |
|
|
|
|
|
|
|
MetadataString(initial_metadata).c_str()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (flag & kFlagMessageData) { |
|
|
|
|
|
|
|
if (arg->GetMessageData() != message_data) { |
|
|
|
|
|
|
|
printf("MESSAGE NOT EQUIVALENT: %s %s\n", |
|
|
|
|
|
|
|
std::string(arg->GetMessageData()).c_str(), |
|
|
|
|
|
|
|
std::string(message_data).c_str()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Matches with grpc_error having error message containing |msg|.
|
|
|
|
|
|
|
|
MATCHER_P(GrpcErrorMessageContains, msg, "") { |
|
|
|
|
|
|
|
return absl::StrContains(grpc_core::StatusToString(arg), msg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BinderTransportTest : public ::testing::Test { |
|
|
|
class BinderTransportTest : public ::testing::Test { |
|
|
|
public: |
|
|
|
public: |
|
|
|
BinderTransportTest() |
|
|
|
BinderTransportTest() |
|
|
@ -144,14 +91,6 @@ class BinderTransportTest : public ::testing::Test { |
|
|
|
GetBinderTransport()->wire_writer.get()); |
|
|
|
GetBinderTransport()->wire_writer.get()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ExpectOutOfBandCloseCalled() { |
|
|
|
|
|
|
|
EXPECT_CALL( |
|
|
|
|
|
|
|
GetWireWriter(), |
|
|
|
|
|
|
|
RpcCall(TransactionMatches( |
|
|
|
|
|
|
|
kFlagOutOfBandClose | (GRPC_STATUS_CANCELLED << kStatusCodeShift), |
|
|
|
|
|
|
|
"", Metadata{}, ""))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void SetUpTestSuite() { grpc_init(); } |
|
|
|
static void SetUpTestSuite() { grpc_init(); } |
|
|
|
static void TearDownTestSuite() { grpc_shutdown(); } |
|
|
|
static void TearDownTestSuite() { grpc_shutdown(); } |
|
|
|
|
|
|
|
|
|
|
@ -193,6 +132,55 @@ void MockCallback(void* arg, grpc_error_handle error) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string MetadataString(const Metadata& a) { |
|
|
|
|
|
|
|
return absl::StrCat( |
|
|
|
|
|
|
|
"{", |
|
|
|
|
|
|
|
absl::StrJoin( |
|
|
|
|
|
|
|
a, ", ", |
|
|
|
|
|
|
|
[](std::string* out, const std::pair<std::string, std::string>& kv) { |
|
|
|
|
|
|
|
out->append( |
|
|
|
|
|
|
|
absl::StrCat("\"", kv.first, "\": \"", kv.second, "\"")); |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
"}"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MetadataEquivalent(Metadata a, Metadata b) { |
|
|
|
|
|
|
|
std::sort(a.begin(), a.end()); |
|
|
|
|
|
|
|
std::sort(b.begin(), b.end()); |
|
|
|
|
|
|
|
return a == b; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Matches with transactions having the desired flag, method_ref,
|
|
|
|
|
|
|
|
// initial_metadata, and message_data.
|
|
|
|
|
|
|
|
MATCHER_P4(TransactionMatches, flag, method_ref, initial_metadata, message_data, |
|
|
|
|
|
|
|
"") { |
|
|
|
|
|
|
|
if (arg->GetFlags() != flag) return false; |
|
|
|
|
|
|
|
if (flag & kFlagPrefix) { |
|
|
|
|
|
|
|
if (arg->GetMethodRef() != method_ref) { |
|
|
|
|
|
|
|
printf("METHOD REF NOT EQ: %s %s\n", |
|
|
|
|
|
|
|
std::string(arg->GetMethodRef()).c_str(), |
|
|
|
|
|
|
|
std::string(method_ref).c_str()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!MetadataEquivalent(arg->GetPrefixMetadata(), initial_metadata)) { |
|
|
|
|
|
|
|
printf("METADATA NOT EQUIVALENT: %s %s\n", |
|
|
|
|
|
|
|
MetadataString(arg->GetPrefixMetadata()).c_str(), |
|
|
|
|
|
|
|
MetadataString(initial_metadata).c_str()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (flag & kFlagMessageData) { |
|
|
|
|
|
|
|
if (arg->GetMessageData() != message_data) return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Matches with grpc_error having error message containing |msg|.
|
|
|
|
|
|
|
|
MATCHER_P(GrpcErrorMessageContains, msg, "") { |
|
|
|
|
|
|
|
return absl::StrContains(grpc_core::StatusToString(arg), msg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
class MetadataEncoder { |
|
|
|
class MetadataEncoder { |
|
|
|
public: |
|
|
|
public: |
|
|
|
void Encode(const grpc_core::Slice& key, const grpc_core::Slice& value) { |
|
|
|
void Encode(const grpc_core::Slice& key, const grpc_core::Slice& value) { |
|
|
@ -213,6 +201,7 @@ class MetadataEncoder { |
|
|
|
private: |
|
|
|
private: |
|
|
|
Metadata metadata_; |
|
|
|
Metadata metadata_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
// Verify that the lower-level metadata has the same content as the gRPC
|
|
|
|
// Verify that the lower-level metadata has the same content as the gRPC
|
|
|
|
// metadata.
|
|
|
|
// metadata.
|
|
|
@ -418,7 +407,6 @@ TEST_F(BinderTransportTest, PerformSendInitialMetadata) { |
|
|
|
EXPECT_CALL(GetWireWriter(), RpcCall(TransactionMatches( |
|
|
|
EXPECT_CALL(GetWireWriter(), RpcCall(TransactionMatches( |
|
|
|
kFlagPrefix, "", kInitialMetadata, ""))); |
|
|
|
kFlagPrefix, "", kInitialMetadata, ""))); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
ExpectOutOfBandCloseCalled(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
@ -442,7 +430,6 @@ TEST_F(BinderTransportTest, PerformSendInitialMetadataMethodRef) { |
|
|
|
RpcCall(TransactionMatches(kFlagPrefix, kMethodRef.substr(1), |
|
|
|
RpcCall(TransactionMatches(kFlagPrefix, kMethodRef.substr(1), |
|
|
|
kInitialMetadata, ""))); |
|
|
|
kInitialMetadata, ""))); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
ExpectOutOfBandCloseCalled(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
@ -465,7 +452,6 @@ TEST_F(BinderTransportTest, PerformSendMessage) { |
|
|
|
GetWireWriter(), |
|
|
|
GetWireWriter(), |
|
|
|
RpcCall(TransactionMatches(kFlagMessageData, "", Metadata{}, kMessage))); |
|
|
|
RpcCall(TransactionMatches(kFlagMessageData, "", Metadata{}, kMessage))); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
ExpectOutOfBandCloseCalled(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
@ -489,7 +475,6 @@ TEST_F(BinderTransportTest, PerformSendTrailingMetadata) { |
|
|
|
EXPECT_CALL(GetWireWriter(), RpcCall(TransactionMatches( |
|
|
|
EXPECT_CALL(GetWireWriter(), RpcCall(TransactionMatches( |
|
|
|
kFlagSuffix, "", kTrailingMetadata, ""))); |
|
|
|
kFlagSuffix, "", kTrailingMetadata, ""))); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
ExpectOutOfBandCloseCalled(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
@ -525,7 +510,6 @@ TEST_F(BinderTransportTest, PerformSendAll) { |
|
|
|
kFlagPrefix | kFlagMessageData | kFlagSuffix, |
|
|
|
kFlagPrefix | kFlagMessageData | kFlagSuffix, |
|
|
|
kMethodRef.substr(1), kInitialMetadata, kMessage))); |
|
|
|
kMethodRef.substr(1), kInitialMetadata, kMessage))); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
ExpectOutOfBandCloseCalled(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
PerformStreamOp(gbs, &op); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
@ -683,7 +667,6 @@ TEST_F(BinderTransportTest, PerformAllOps) { |
|
|
|
RpcCall(TransactionMatches( |
|
|
|
RpcCall(TransactionMatches( |
|
|
|
kFlagPrefix | kFlagMessageData | kFlagSuffix, |
|
|
|
kFlagPrefix | kFlagMessageData | kFlagSuffix, |
|
|
|
kMethodRef.substr(1), kSendInitialMetadata, kSendMessage))); |
|
|
|
kMethodRef.substr(1), kSendInitialMetadata, kSendMessage))); |
|
|
|
ExpectOutOfBandCloseCalled(); |
|
|
|
|
|
|
|
Expectation on_complete = EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
Expectation on_complete = EXPECT_CALL(mock_on_complete, Callback); |
|
|
|
|
|
|
|
|
|
|
|
// Recv callbacks can happen after the on_complete callback.
|
|
|
|
// Recv callbacks can happen after the on_complete callback.
|
|
|
@ -737,7 +720,6 @@ TEST_F(BinderTransportTest, WireWriterRpcCallErrorPropagates) { |
|
|
|
EXPECT_CALL(mock_on_complete1, Callback(absl::OkStatus())); |
|
|
|
EXPECT_CALL(mock_on_complete1, Callback(absl::OkStatus())); |
|
|
|
EXPECT_CALL(mock_on_complete2, |
|
|
|
EXPECT_CALL(mock_on_complete2, |
|
|
|
Callback(GrpcErrorMessageContains("WireWriter::RpcCall failed"))); |
|
|
|
Callback(GrpcErrorMessageContains("WireWriter::RpcCall failed"))); |
|
|
|
ExpectOutOfBandCloseCalled(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Metadata kInitialMetadata = {}; |
|
|
|
const Metadata kInitialMetadata = {}; |
|
|
|
grpc_transport_stream_op_batch op1{}; |
|
|
|
grpc_transport_stream_op_batch op1{}; |
|
|
|