Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Dec 19, 2024
1 parent 5a8a1e7 commit 877a782
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 39 deletions.
4 changes: 3 additions & 1 deletion src/core/ext/transport/chaotic_good/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ absl::StatusOr<Frame> ParseFrame(const FrameHeader& header,
case FrameType::kBeginMessage:
return DeserializeFrame<BeginMessageFrame>(header, std::move(payload));
default:
return absl::InternalError("bah");
return absl::InternalError(
absl::StrCat("Unknown frame type: ", header.ToString(),
" payload:", payload.Length(), "b"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/ext/transport/chaotic_good/frame_header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ std::string FrameTypeString(FrameType type) {
case FrameType::kMessageChunk:
return "MessageChunk";
}
return absl::StrCat("Unknown[", static_cast<int>(type), "]");
return absl::StrCat("Unknown[0x", absl::Hex(static_cast<int>(type)), "]");
}

} // namespace chaotic_good
Expand Down
41 changes: 6 additions & 35 deletions test/core/transport/chaotic_good/client_transport_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ namespace grpc_core {
namespace chaotic_good {
namespace testing {

class MockClientConnectionFactory : public ClientConnectionFactory {
public:
MOCK_METHOD(PendingConnection, Connect, (absl::string_view), (override));
void Orphaned() final {}
};

ClientMetadataHandle TestInitialMetadata() {
auto md = Arena::MakePooledForOverwrite<ClientMetadata>();
md->Set(HttpPathMetadata(), Slice::FromStaticString("/demo.Service/Step"));
Expand Down Expand Up @@ -101,23 +95,8 @@ ChannelArgs MakeChannelArgs(
std::move(event_engine));
}

template <typename... PromiseEndpoints>
Config MakeConfig(const ChannelArgs& channel_args,
PromiseEndpoints... promise_endpoints) {
Config config(channel_args);
auto name_endpoint = [i = 0]() mutable { return absl::StrCat(++i); };
std::vector<int> this_is_only_here_to_unpack_the_following_statement{
(config.ServerAddPendingDataEndpoint(
ImmediateConnection(name_endpoint(), std::move(promise_endpoints))),
0)...};
return config;
}

TEST_F(TransportTest, AddOneStream) {
MockPromiseEndpoint control_endpoint(1000);
MockPromiseEndpoint data_endpoint(1001);
auto client_connection_factory =
MakeRefCounted<StrictMock<MockClientConnectionFactory>>();
MockFrameTransport frame_transport;
static const std::string many_as(1024 * 1024, 'a');
const auto server_initial_metadata =
EncodeProto<chaotic_good_frame::ServerMetadata>("message: 'hello'");
Expand All @@ -142,22 +121,14 @@ TEST_F(TransportTest, AddOneStream) {
.WillOnce(Return(false));
auto channel_args = MakeChannelArgs(event_engine());
auto transport = MakeOrphanable<ChaoticGoodClientTransport>(
channel_args, std::move(control_endpoint.promise_endpoint),
MakeConfig(channel_args, std::move(data_endpoint.promise_endpoint)),
client_connection_factory);
channel_args, frame_transport, MessageChunker(0, 1));
auto call = MakeCall(TestInitialMetadata());
StrictMock<MockFunction<void()>> on_done;
EXPECT_CALL(on_done, Call());
control_endpoint.ExpectWrite(
{SerializedFrameHeader(FrameType::kClientInitialMetadata, 0, 1,
client_initial_metadata.length()),
client_initial_metadata.Copy()},
nullptr);
control_endpoint.ExpectWrite(
{SerializedFrameHeader(FrameType::kMessage, 0, 1, 1),
EventEngineSlice::FromCopiedString("0"),
SerializedFrameHeader(FrameType::kClientEndOfStream, 0, 1, 0)},
nullptr);
frame_transport.ExpectWrite(MakeProtoFrame<ClientInitialMetadataFrame>(
1, "path: '/demo.Service/Step'"));
frame_transport.ExpectWrite(MakeMessageFrame(1, many_as));
frame_transport.ExpectWrite(ClientEndOfStreamFrame(1));
transport->StartCall(call.handler.StartCall());
call.initiator.SpawnGuarded("test-send",
[initiator = call.initiator]() mutable {
Expand Down
5 changes: 3 additions & 2 deletions test/core/transport/chaotic_good/mock_frame_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ void MockFrameTransport::StartWriting(
void MockFrameTransport::Read(Frame frame) {
SliceBuffer buffer;
auto& frame_interface = absl::ConvertVariantTo<FrameInterface&>(frame);
LOG(INFO) << "Read " << frame_interface.ToString();
auto header = frame_interface.MakeHeader();
frame_interface.SerializePayload(buffer);
reader_.UnbufferedImmediateSend(
IncomingFrame(frame_interface.MakeHeader(), std::move(buffer)));
reader_.UnbufferedImmediateSend(IncomingFrame(header, std::move(buffer)));
}

} // namespace testing
Expand Down

0 comments on commit 877a782

Please sign in to comment.