diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b4ec17519dd7..de3061f7ee39e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1509,6 +1509,7 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx xds_routing_end2end_test) endif() add_dependencies(buildtests_cxx xds_stats_watcher_test) + add_dependencies(buildtests_cxx xds_transport_grpc_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx xds_wrr_end2end_test) endif() @@ -29740,6 +29741,39 @@ target_link_libraries(xds_stats_watcher_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(xds_transport_grpc_test + test/core/ext/xds/xds_transport_grpc_test.cc +) +target_compile_features(xds_transport_grpc_test PUBLIC cxx_std_14) +target_include_directories(xds_transport_grpc_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(xds_transport_grpc_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index acc1db59f45df..e431decd49518 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -18658,6 +18658,17 @@ targets: - grpcpp_channelz - grpc_test_util - grpc++_test_config +- name: xds_transport_grpc_test + gtest: true + build: test + language: c++ + headers: [] + src: + - test/core/ext/xds/xds_transport_grpc_test.cc + deps: + - gtest + - grpc_test_util + uses_polling: false - name: xds_wrr_end2end_test gtest: true build: test diff --git a/test/core/ext/xds/BUILD b/test/core/ext/xds/BUILD new file mode 100644 index 0000000000000..3e1a892937202 --- /dev/null +++ b/test/core/ext/xds/BUILD @@ -0,0 +1,32 @@ +# 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. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") + +licenses(["notice"]) + +grpc_package(name = "test/core/ext/xds") + +grpc_cc_test( + name = "xds_transport_grpc_test", + srcs = ["xds_transport_grpc_test.cc"], + external_deps = ["gtest"], + language = "c++", + uses_event_engine = False, + uses_polling = False, + deps = [ + "//src/core:grpc_xds_client", + "//test/core/util:grpc_test_util", + ], +) diff --git a/test/core/ext/xds/xds_transport_grpc_test.cc b/test/core/ext/xds/xds_transport_grpc_test.cc new file mode 100644 index 0000000000000..8128497b7a53d --- /dev/null +++ b/test/core/ext/xds/xds_transport_grpc_test.cc @@ -0,0 +1,91 @@ +// Copyright 2021 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. + +#include "src/core/ext/xds/xds_transport_grpc.h" + +#include +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "src/core/ext/xds/xds_bootstrap_grpc.h" +#include "test/core/util/test_config.h" + +namespace grpc_core { +namespace testing { +namespace { + +using EventHandlerEvent = absl::variant< + bool, absl::Status, + std::pair>>; + +class TestEventHandler + : public XdsTransportFactory::XdsTransport::StreamingCall::EventHandler { + public: + TestEventHandler(std::vector* events) : events_(events) {} + + void OnRequestSent(bool ok) override { events_->emplace_back(ok); } + + void OnRecvMessage( + absl::string_view payload, + RefCountedPtr< + XdsTransportFactory::XdsTransport::StreamingCall::ReadDelayHandle> + read_delay_handle) override { + events_->emplace_back( + std::make_pair(std::string(payload), std::move(read_delay_handle))); + } + + void OnStatusReceived(absl::Status status) override { + events_->emplace_back(std::move(status)); + } + + private: + std::vector* events_; +}; + +TEST(GrpcTransportTest, WaitsWithAdsRead) { + ExecCtx exec_ctx; + ChannelArgs args; + auto factory = MakeOrphanable(args); + GrpcXdsBootstrap::GrpcXdsServer server; + + absl::Status status; + + auto transport = factory->Create( + server, + [](auto s) { + gpr_log(GPR_ERROR, "%s", std::string(s.message()).c_str()); + }, + &status); + std::vector events; + auto call = transport->CreateStreamingCall( + "boop", std::make_unique(&events)); + + EXPECT_THAT(events, ::testing::IsEmpty()); +} + +} // namespace +} // namespace testing +} // namespace grpc_core + +int main(int argc, char** argv) { + grpc::testing::TestEnvironment env(&argc, argv); + ::testing::InitGoogleTest(&argc, argv); + grpc_init(); + const auto result = RUN_ALL_TESTS(); + grpc_shutdown(); + return result; +} diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index ffa7f310edbdb..bd2f290296852 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -11867,6 +11867,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "xds_transport_grpc_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false,