Matches the SetDefaultEventEngineFactory definition to its declaration (#28707)

* Matches the SetDefaultEventEngineFactory definition to its declaration

+`const`

* Add smoke test for SetDefaultEventEngineFactory

* Automated change: Fix sanity tests

* anonymous namespace

Co-authored-by: drfloob <drfloob@users.noreply.github.com>
pull/13174/head^2
AJ Heller 3 years ago committed by GitHub
parent f33c587c2a
commit 47bc953a06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      CMakeLists.txt
  2. 9
      build_autogenerated.yaml
  3. 5
      src/core/lib/event_engine/event_engine_factory.cc
  4. 10
      test/core/event_engine/BUILD
  5. 50
      test/core/event_engine/smoke_test.cc
  6. 24
      tools/run_tests/generated/tests.json

36
CMakeLists.txt generated

@ -979,6 +979,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx settings_timeout_test)
add_dependencies(buildtests_cxx shutdown_test)
add_dependencies(buildtests_cxx simple_request_bad_client_test)
add_dependencies(buildtests_cxx smoke_test)
add_dependencies(buildtests_cxx sockaddr_utils_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx stack_tracer_test)
@ -15173,6 +15174,41 @@ target_link_libraries(simple_request_bad_client_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(smoke_test
test/core/event_engine/smoke_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(smoke_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(smoke_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)

@ -7750,6 +7750,15 @@ targets:
- test/core/end2end/cq_verifier.cc
deps:
- grpc_test_util
- name: smoke_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/event_engine/smoke_test.cc
deps:
- grpc_test_util
- name: sockaddr_utils_test
gtest: true
build: test

@ -21,7 +21,8 @@ namespace grpc_event_engine {
namespace experimental {
namespace {
std::function<std::unique_ptr<EventEngine>()>* g_event_engine_factory = nullptr;
const std::function<std::unique_ptr<EventEngine>()>* g_event_engine_factory =
nullptr;
grpc_core::Mutex* g_mu = new grpc_core::Mutex();
} // namespace
@ -31,7 +32,7 @@ EventEngine* GetDefaultEventEngine() {
}
void SetDefaultEventEngineFactory(
std::function<std::unique_ptr<EventEngine>()>* factory) {
const std::function<std::unique_ptr<EventEngine>()>* factory) {
grpc_core::MutexLock lock(g_mu);
g_event_engine_factory = factory;
}

@ -49,3 +49,13 @@ grpc_cc_library(
# Ensure the linker doesn't throw away test cases.
alwayslink = 1,
)
grpc_cc_test(
name = "smoke_test",
srcs = ["smoke_test.cc"],
external_deps = ["gtest"],
deps = [
"//:grpc",
"//test/core/util:grpc_test_util",
],
)

@ -0,0 +1,50 @@
// Copyright 2022 The 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 <grpc/support/port_platform.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <grpc/event_engine/event_engine.h>
#include <grpc/grpc.h>
#include "test/core/util/test_config.h"
namespace {
using ::testing::MockFunction;
class EventEngineSmokeTest : public testing::Test {};
TEST_F(EventEngineSmokeTest, SetDefaultEventEngineFactoryLinks) {
// See https://github.com/grpc/grpc/pull/28707
testing::MockFunction<
std::unique_ptr<grpc_event_engine::experimental::EventEngine>()>
factory;
EXPECT_CALL(factory, Call()).Times(1);
auto stdfn_fact = factory.AsStdFunction();
grpc_event_engine::experimental::SetDefaultEventEngineFactory(&stdfn_fact);
EXPECT_EQ(nullptr, grpc_event_engine::experimental::CreateEventEngine());
}
} // namespace
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
grpc::testing::TestEnvironment env(argc, argv);
grpc_init();
auto result = RUN_ALL_TESTS();
grpc_shutdown();
return result;
}

@ -6475,6 +6475,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": "smoke_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save