[Test] Add concurrent test for session reuse (#34293)

Add a test that runs concurrent requests using session caching.
pull/34180/head
Gregory Cooke 1 year ago committed by GitHub
parent 1986007e1e
commit 8d62fc2b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 139
      CMakeLists.txt
  2. 80
      build_autogenerated.yaml
  3. 26
      test/cpp/end2end/BUILD
  4. 170
      test/cpp/end2end/ssl_credentials_test.cc
  5. 72
      tools/run_tests/generated/tests.json

139
CMakeLists.txt generated

@ -1319,7 +1319,6 @@ if(gRPC_BUILD_TESTS)
endif()
add_dependencies(buildtests_cxx sorted_pack_test)
add_dependencies(buildtests_cxx spinlock_test)
add_dependencies(buildtests_cxx ssl_credentials_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx ssl_transport_security_test)
endif()
@ -1373,11 +1372,13 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx test_core_iomgr_load_file_test)
add_dependencies(buildtests_cxx test_core_iomgr_timer_heap_test)
add_dependencies(buildtests_cxx test_core_security_credentials_test)
add_dependencies(buildtests_cxx test_core_security_ssl_credentials_test)
add_dependencies(buildtests_cxx test_core_slice_slice_buffer_test)
add_dependencies(buildtests_cxx test_core_slice_slice_test)
add_dependencies(buildtests_cxx test_core_transport_chaotic_good_frame_test)
add_dependencies(buildtests_cxx test_core_transport_chttp2_frame_test)
add_dependencies(buildtests_cxx test_cpp_client_credentials_test)
add_dependencies(buildtests_cxx test_cpp_end2end_ssl_credentials_test)
add_dependencies(buildtests_cxx test_cpp_server_credentials_test)
add_dependencies(buildtests_cxx test_cpp_util_slice_test)
add_dependencies(buildtests_cxx test_cpp_util_time_test)
@ -22351,49 +22352,6 @@ target_link_libraries(spinlock_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(ssl_credentials_test
test/core/security/ssl_credentials_test.cc
test/core/util/cmdline.cc
test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc
test/core/util/histogram.cc
test/core/util/mock_endpoint.cc
test/core/util/parse_hexstring.cc
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.cc
test/core/util/slice_splitter.cc
test/core/util/tracer_util.cc
)
target_compile_features(ssl_credentials_test PUBLIC cxx_std_14)
target_include_directories(ssl_credentials_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(ssl_credentials_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)
@ -23748,6 +23706,49 @@ target_link_libraries(test_core_security_credentials_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(test_core_security_ssl_credentials_test
test/core/security/ssl_credentials_test.cc
test/core/util/cmdline.cc
test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc
test/core/util/histogram.cc
test/core/util/mock_endpoint.cc
test/core/util/parse_hexstring.cc
test/core/util/passthru_endpoint.cc
test/core/util/resolve_localhost_ip46.cc
test/core/util/slice_splitter.cc
test/core/util/tracer_util.cc
)
target_compile_features(test_core_security_ssl_credentials_test PUBLIC cxx_std_14)
target_include_directories(test_core_security_ssl_credentials_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(test_core_security_ssl_credentials_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -24186,6 +24187,56 @@ target_link_libraries(test_cpp_client_credentials_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(test_cpp_end2end_ssl_credentials_test
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.h
test/cpp/end2end/ssl_credentials_test.cc
test/cpp/end2end/test_service_impl.cc
)
target_compile_features(test_cpp_end2end_ssl_credentials_test PUBLIC cxx_std_14)
target_include_directories(test_cpp_end2end_ssl_credentials_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(test_cpp_end2end_ssl_credentials_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
grpc++_test_util
)
endif()
if(gRPC_BUILD_TESTS)

@ -14771,38 +14771,6 @@ targets:
- gtest
- grpc_test_util
uses_polling: false
- name: ssl_credentials_test
gtest: true
build: test
language: c++
headers:
- test/core/util/cmdline.h
- test/core/util/evaluate_args_test_util.h
- test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h
- test/core/util/histogram.h
- test/core/util/mock_authorization_endpoint.h
- test/core/util/mock_endpoint.h
- test/core/util/parse_hexstring.h
- test/core/util/passthru_endpoint.h
- test/core/util/resolve_localhost_ip46.h
- test/core/util/slice_splitter.h
- test/core/util/tracer_util.h
src:
- test/core/security/ssl_credentials_test.cc
- test/core/util/cmdline.cc
- test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc
- test/core/util/mock_endpoint.cc
- test/core/util/parse_hexstring.cc
- test/core/util/passthru_endpoint.cc
- test/core/util/resolve_localhost_ip46.cc
- test/core/util/slice_splitter.cc
- test/core/util/tracer_util.cc
deps:
- gtest
- grpc_test_util
- name: ssl_transport_security_test
gtest: true
build: test
@ -15550,6 +15518,38 @@ targets:
deps:
- gtest
- grpc_test_util
- name: test_core_security_ssl_credentials_test
gtest: true
build: test
language: c++
headers:
- test/core/util/cmdline.h
- test/core/util/evaluate_args_test_util.h
- test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h
- test/core/util/histogram.h
- test/core/util/mock_authorization_endpoint.h
- test/core/util/mock_endpoint.h
- test/core/util/parse_hexstring.h
- test/core/util/passthru_endpoint.h
- test/core/util/resolve_localhost_ip46.h
- test/core/util/slice_splitter.h
- test/core/util/tracer_util.h
src:
- test/core/security/ssl_credentials_test.cc
- test/core/util/cmdline.cc
- test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc
- test/core/util/mock_endpoint.cc
- test/core/util/parse_hexstring.cc
- test/core/util/passthru_endpoint.cc
- test/core/util/resolve_localhost_ip46.cc
- test/core/util/slice_splitter.cc
- test/core/util/tracer_util.cc
deps:
- gtest
- grpc_test_util
- name: test_core_slice_slice_buffer_test
gtest: true
build: test
@ -16190,6 +16190,22 @@ targets:
- gtest
- grpc++
- grpc_test_util
- name: test_cpp_end2end_ssl_credentials_test
gtest: true
build: test
language: c++
headers:
- test/cpp/end2end/test_service_impl.h
src:
- src/proto/grpc/testing/echo.proto
- src/proto/grpc/testing/echo_messages.proto
- src/proto/grpc/testing/simple_messages.proto
- src/proto/grpc/testing/xds/v3/orca_load_report.proto
- test/cpp/end2end/ssl_credentials_test.cc
- test/cpp/end2end/test_service_impl.cc
deps:
- gtest
- grpc++_test_util
- name: test_cpp_server_credentials_test
gtest: true
build: test

@ -1028,3 +1028,29 @@ grpc_cc_test(
"//test/cpp/util:test_util",
],
)
grpc_cc_test(
name = "ssl_credentials_test",
srcs = ["ssl_credentials_test.cc"],
data = [
"//src/core/tsi/test_creds:ca.pem",
"//src/core/tsi/test_creds:client.key",
"//src/core/tsi/test_creds:client.pem",
"//src/core/tsi/test_creds:server1.key",
"//src/core/tsi/test_creds:server1.pem",
],
external_deps = [
"gtest",
],
tags = ["ssl_credentials_test"],
deps = [
":test_service_impl",
"//:gpr",
"//:grpc",
"//:grpc++",
"//src/proto/grpc/testing:echo_messages_proto",
"//src/proto/grpc/testing:echo_proto",
"//test/core/util:grpc_test_util",
"//test/cpp/util:test_util",
],
)

@ -0,0 +1,170 @@
//
//
// 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.
//
//
#include <memory>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/synchronization/notification.h"
#include <grpc/grpc_security.h>
#include <grpcpp/channel.h>
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/end2end/test_service_impl.h"
namespace grpc {
namespace testing {
namespace {
constexpr char kCaCertPath[] = "src/core/tsi/test_creds/ca.pem";
constexpr char kServerCertPath[] = "src/core/tsi/test_creds/server1.pem";
constexpr char kServerKeyPath[] = "src/core/tsi/test_creds/server1.key";
constexpr char kClientCertPath[] = "src/core/tsi/test_creds/client.pem";
constexpr char kClientKeyPath[] = "src/core/tsi/test_creds/client.key";
constexpr char kMessage[] = "Hello";
std::string ReadFile(const std::string& file_path) {
grpc_slice slice;
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(file_path.c_str(), 0, &slice)));
std::string file_contents(grpc_core::StringViewFromSlice(slice));
grpc_slice_unref(slice);
return file_contents;
}
class SslCredentialsTest : public ::testing::Test {
protected:
void RunServer(absl::Notification* notification) {
std::string root_cert = ReadFile(kCaCertPath);
grpc::SslServerCredentialsOptions::PemKeyCertPair key_cert_pair = {
ReadFile(kServerKeyPath), ReadFile(kServerCertPath)};
// TODO(gtcooke94) Parametrize this test for TLS and mTLS as well
grpc::SslServerCredentialsOptions ssl_options;
ssl_options.pem_key_cert_pairs.push_back(key_cert_pair);
ssl_options.pem_root_certs = root_cert;
ssl_options.force_client_auth = true;
grpc::ServerBuilder builder;
TestServiceImpl service_;
builder.AddListeningPort(server_addr_,
grpc::SslServerCredentials(ssl_options));
builder.RegisterService("foo.test.google.fr", &service_);
server_ = builder.BuildAndStart();
notification->Notify();
server_->Wait();
}
void TearDown() override {
if (server_ != nullptr) {
server_->Shutdown();
server_thread_->join();
delete server_thread_;
}
}
TestServiceImpl service_;
std::unique_ptr<Server> server_ = nullptr;
std::thread* server_thread_ = nullptr;
std::string server_addr_;
};
void DoRpc(const std::string& server_addr,
const SslCredentialsOptions& ssl_options,
grpc_ssl_session_cache* cache, bool expect_session_reuse) {
ChannelArguments channel_args;
channel_args.SetPointer(std::string(GRPC_SSL_SESSION_CACHE_ARG), cache);
channel_args.SetSslTargetNameOverride("foo.test.google.fr");
std::shared_ptr<Channel> channel = grpc::CreateCustomChannel(
server_addr, grpc::SslCredentials(ssl_options), channel_args);
auto stub = grpc::testing::EchoTestService::NewStub(channel);
grpc::testing::EchoRequest request;
grpc::testing::EchoResponse response;
request.set_message(kMessage);
ClientContext context;
context.set_deadline(grpc_timeout_milliseconds_to_deadline(
/*time_ms=*/5000 * grpc_test_slowdown_factor()));
grpc::Status result = stub->Echo(&context, request, &response);
EXPECT_TRUE(result.ok());
if (!result.ok()) {
gpr_log(GPR_ERROR, "%s, %s", result.error_message().c_str(),
result.error_details().c_str());
}
EXPECT_EQ(response.message(), kMessage);
std::shared_ptr<const AuthContext> auth_context = context.auth_context();
std::vector<grpc::string_ref> properties =
auth_context->FindPropertyValues(GRPC_SSL_SESSION_REUSED_PROPERTY);
ASSERT_EQ(properties.size(), 1u);
if (expect_session_reuse) {
EXPECT_EQ("true", ToString(properties[0]));
} else {
EXPECT_EQ("false", ToString(properties[0]));
}
}
TEST_F(SslCredentialsTest, ConcurrentResumption) {
server_addr_ = absl::StrCat("localhost:",
std::to_string(grpc_pick_unused_port_or_die()));
absl::Notification notification;
server_thread_ = new std::thread([&]() { RunServer(&notification); });
notification.WaitForNotification();
std::string root_cert = ReadFile(kCaCertPath);
std::string client_key = ReadFile(kClientKeyPath);
std::string client_cert = ReadFile(kClientCertPath);
grpc::SslCredentialsOptions ssl_options;
ssl_options.pem_root_certs = root_cert;
ssl_options.pem_private_key = client_key;
ssl_options.pem_cert_chain = client_cert;
grpc_ssl_session_cache* cache = grpc_ssl_session_cache_create_lru(16);
DoRpc(server_addr_, ssl_options, cache, /*expect_session_reuse=*/false);
std::vector<std::thread> threads;
threads.reserve(10);
for (int i = 0; i < 10; i++) {
threads.push_back(std::thread([&]() {
DoRpc(server_addr_, ssl_options, cache, /*expect_session_reuse=*/true);
}));
}
for (auto& t : threads) {
t.join();
}
grpc_ssl_session_cache_destroy(cache);
}
} // namespace
} // namespace testing
} // namespace grpc
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}

@ -9195,30 +9195,6 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "ssl_credentials_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
@ -10039,6 +10015,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": "test_core_security_ssl_credentials_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
@ -10159,6 +10159,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": "test_cpp_end2end_ssl_credentials_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save