Skip to content

Commit

Permalink
fixup: new test
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneo committed Nov 8, 2023
1 parent b721fd4 commit a7310dd
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 0 deletions.
34 changes: 34 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions test/core/ext/xds/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)
91 changes: 91 additions & 0 deletions test/core/ext/xds/xds_transport_grpc_test.cc
Original file line number Diff line number Diff line change
@@ -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 <utility>
#include <vector>

#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<std::string, RefCountedPtr<XdsTransportFactory::XdsTransport::
StreamingCall::ReadDelayHandle>>>;

class TestEventHandler
: public XdsTransportFactory::XdsTransport::StreamingCall::EventHandler {
public:
TestEventHandler(std::vector<EventHandlerEvent>* 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<EventHandlerEvent>* events_;
};

TEST(GrpcTransportTest, WaitsWithAdsRead) {
ExecCtx exec_ctx;
ChannelArgs args;
auto factory = MakeOrphanable<GrpcXdsTransportFactory>(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<EventHandlerEvent> events;
auto call = transport->CreateStreamingCall(
"boop", std::make_unique<TestEventHandler>(&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;
}
24 changes: 24 additions & 0 deletions tools/run_tests/generated/tests.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7310dd

Please sign in to comment.