Skip to content

Commit

Permalink
[PH2][Test][Transport] Refactor Chaotic Good Tests (grpc#38791)
Browse files Browse the repository at this point in the history
[PH2][Test][Transport] Refactor Chaotic Good Tests

Moving the tests to a common util folder where they can be used by both Chaotic Good and HTTP2 Transport.

Closes grpc#38791

COPYBARA_INTEGRATE_REVIEW=grpc#38791 from tanvi-jagtap:move_common_test_file_to_util b8e5704
PiperOrigin-RevId: 729325544
  • Loading branch information
tanvi-jagtap authored and copybara-github committed Feb 21, 2025
1 parent 211f9ec commit 84d143b
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 27 deletions.
12 changes: 7 additions & 5 deletions test/core/transport/chaotic_good/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ grpc_package(
)

grpc_cc_library(
name = "transport_test",
name = "transport_test_helper",
testonly = 1,
srcs = ["transport_test.cc"],
hdrs = ["transport_test.h"],
srcs = ["transport_test_helper.cc"],
hdrs = ["transport_test_helper.h"],
external_deps = ["gtest"],
deps = [
"//:iomgr_timer",
Expand Down Expand Up @@ -135,7 +135,7 @@ grpc_cc_test(
uses_event_engine = False,
uses_polling = False,
deps = [
"transport_test",
"transport_test_helper",
"//:grpc",
"//:grpc_public_hdrs",
"//src/core:arena",
Expand All @@ -145,6 +145,7 @@ grpc_cc_test(
"//src/core:seq",
"//src/core:slice_buffer",
"//test/core/transport/util:mock_promise_endpoint",
"//test/core/transport/util:transport_test",
],
)

Expand Down Expand Up @@ -197,7 +198,7 @@ grpc_cc_test(
uses_event_engine = False,
uses_polling = False,
deps = [
"transport_test",
"transport_test_helper",
"//:grpc",
"//:grpc_public_hdrs",
"//:iomgr_timer",
Expand All @@ -212,6 +213,7 @@ grpc_cc_test(
"//test/core/event_engine/fuzzing_event_engine",
"//test/core/event_engine/fuzzing_event_engine:fuzzing_event_engine_cc_proto",
"//test/core/transport/util:mock_promise_endpoint",
"//test/core/transport/util:transport_test",
],
)

Expand Down
4 changes: 3 additions & 1 deletion test/core/transport/chaotic_good/client_transport_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@
#include "gtest/gtest.h"
#include "src/core/config/core_configuration.h"
#include "src/core/ext/transport/chaotic_good/chaotic_good_frame.pb.h"
#include "src/core/ext/transport/chaotic_good/frame.h"
#include "src/core/lib/promise/if.h"
#include "src/core/lib/promise/loop.h"
#include "src/core/lib/promise/seq.h"
#include "src/core/lib/resource_quota/arena.h"
#include "src/core/lib/slice/slice_buffer.h"
#include "src/core/lib/transport/metadata_batch.h"
#include "test/core/transport/chaotic_good/transport_test.h"
#include "test/core/transport/chaotic_good/transport_test_helper.h"
#include "test/core/transport/util/mock_promise_endpoint.h"
#include "test/core/transport/util/transport_test.h"

using testing::MockFunction;
using testing::Return;
Expand Down
3 changes: 2 additions & 1 deletion test/core/transport/chaotic_good/server_transport_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
#include "src/core/util/ref_counted_ptr.h"
#include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h"
#include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h"
#include "test/core/transport/chaotic_good/transport_test.h"
#include "test/core/transport/chaotic_good/transport_test_helper.h"
#include "test/core/transport/util/mock_promise_endpoint.h"
#include "test/core/transport/util/transport_test.h"

using testing::_;
using testing::MockFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "test/core/transport/chaotic_good/transport_test.h"
#include "test/core/transport/chaotic_good/transport_test_helper.h"

namespace grpc_core {
namespace chaotic_good {
Expand Down
55 changes: 55 additions & 0 deletions test/core/transport/chaotic_good/transport_test_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GRPC_TEST_CORE_TRANSPORT_CHAOTIC_GOOD_TRANSPORT_TEST_HELPER_H
#define GRPC_TEST_CORE_TRANSPORT_CHAOTIC_GOOD_TRANSPORT_TEST_HELPER_H

#include <google/protobuf/text_format.h>

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "src/core/ext/transport/chaotic_good/frame.h"
#include "src/core/lib/event_engine/event_engine_context.h"
#include "src/core/lib/iomgr/timer_manager.h"
#include "src/core/lib/resource_quota/memory_quota.h"
#include "src/core/lib/resource_quota/resource_quota.h"
#include "src/core/lib/transport/call_arena_allocator.h"
#include "src/core/lib/transport/call_spine.h"
#include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h"
#include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h"

namespace grpc_core {
namespace chaotic_good {
namespace testing {

grpc_event_engine::experimental::Slice SerializedFrameHeader(
FrameType type, uint16_t payload_connection_id, uint32_t stream_id,
uint32_t payload_length);

grpc_event_engine::experimental::Slice Zeros(uint32_t length);

template <typename T>
grpc_event_engine::experimental::Slice EncodeProto(const std::string& fields) {
T msg;
CHECK(google::protobuf::TextFormat::ParseFromString(fields, &msg));
std::string out;
CHECK(msg.SerializeToString(&out));
return grpc_event_engine::experimental::Slice::FromCopiedString(out);
}

} // namespace testing
} // namespace chaotic_good
} // namespace grpc_core

#endif // GRPC_TEST_CORE_TRANSPORT_CHAOTIC_GOOD_TRANSPORT_TEST_HELPER_H
14 changes: 14 additions & 0 deletions test/core/transport/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ grpc_cc_library(
"//src/core:grpc_promise_endpoint",
],
)

grpc_cc_library(
name = "transport_test",
testonly = 1,
hdrs = ["transport_test.h"],
external_deps = ["gtest"],
deps = [
"//:iomgr_timer",
"//src/core:memory_quota",
"//src/core:resource_quota",
"//test/core/event_engine/fuzzing_event_engine",
"//test/core/event_engine/fuzzing_event_engine:fuzzing_event_engine_cc_proto",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GRPC_TEST_CORE_TRANSPORT_CHAOTIC_GOOD_TRANSPORT_TEST_H
#define GRPC_TEST_CORE_TRANSPORT_CHAOTIC_GOOD_TRANSPORT_TEST_H
#ifndef GRPC_TEST_CORE_TRANSPORT_UTIL_TRANSPORT_TEST_H
#define GRPC_TEST_CORE_TRANSPORT_UTIL_TRANSPORT_TEST_H

#include <google/protobuf/text_format.h>

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "src/core/ext/transport/chaotic_good/frame.h"
#include "src/core/lib/event_engine/event_engine_context.h"
#include "src/core/lib/iomgr/timer_manager.h"
#include "src/core/lib/resource_quota/memory_quota.h"
Expand Down Expand Up @@ -74,23 +73,8 @@ class TransportTest : public ::testing::Test {
1024)};
};

grpc_event_engine::experimental::Slice SerializedFrameHeader(
FrameType type, uint16_t payload_connection_id, uint32_t stream_id,
uint32_t payload_length);

grpc_event_engine::experimental::Slice Zeros(uint32_t length);

template <typename T>
grpc_event_engine::experimental::Slice EncodeProto(const std::string& fields) {
T msg;
CHECK(google::protobuf::TextFormat::ParseFromString(fields, &msg));
std::string out;
CHECK(msg.SerializeToString(&out));
return grpc_event_engine::experimental::Slice::FromCopiedString(out);
}

} // namespace testing
} // namespace chaotic_good
} // namespace grpc_core

#endif // GRPC_TEST_CORE_TRANSPORT_CHAOTIC_GOOD_TRANSPORT_TEST_H
#endif // GRPC_TEST_CORE_TRANSPORT_UTIL_TRANSPORT_TEST_H

0 comments on commit 84d143b

Please sign in to comment.