core_configuration_test.cc
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <chrono>
18 #include <thread>
19 
20 #include <gtest/gtest.h>
21 
22 namespace grpc_core {
23 
24 // Allow substitution of config builder - in real code this would iterate
25 // through all plugins
26 namespace {
27 using ConfigBuilderFunction = std::function<void(CoreConfiguration::Builder*)>;
28 ConfigBuilderFunction g_mock_builder;
29 } // namespace
30 
32  g_mock_builder(builder);
33 }
34 
35 namespace {
36 // Helper for testing - clear out any state, rebuild configuration with fn being
37 // the initializer
38 void InitConfigWithBuilder(ConfigBuilderFunction fn) {
40  g_mock_builder = fn;
42  g_mock_builder = nullptr;
43 }
44 
45 TEST(ConfigTest, NoopConfig) {
46  InitConfigWithBuilder([](CoreConfiguration::Builder*) {});
48 }
49 
50 TEST(ConfigTest, ThreadedInit) {
52  g_mock_builder = [](CoreConfiguration::Builder*) {
53  std::this_thread::sleep_for(std::chrono::seconds(1));
54  };
55  std::vector<std::thread> threads;
56  threads.reserve(64);
57  for (int i = 0; i < 64; i++) {
58  threads.push_back(std::thread([]() { CoreConfiguration::Get(); }));
59  }
60  for (auto& t : threads) {
61  t.join();
62  }
63  g_mock_builder = nullptr;
65 }
66 } // namespace
67 
68 } // namespace grpc_core
69 
70 int main(int argc, char** argv) {
71  ::testing::InitGoogleTest(&argc, argv);
72  return RUN_ALL_TESTS();
73 }
absl::time_internal::cctz::seconds
std::chrono::duration< std::int_fast64_t > seconds
Definition: abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h:40
core_configuration.h
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::TEST
TEST(AvlTest, NoOp)
Definition: avl_test.cc:21
threads
static uv_thread_t * threads
Definition: threadpool.c:38
profile_analyzer.builder
builder
Definition: profile_analyzer.py:159
generate-asm-lcov.fn
fn
Definition: generate-asm-lcov.py:146
grpc_core::CoreConfiguration::Get
static const CoreConfiguration & Get()
Definition: core_configuration.h:82
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
main
int main(int argc, char **argv)
Definition: core_configuration_test.cc:70
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
absl::str_format_internal::LengthMod::t
@ t
grpc_core::BuildCoreConfiguration
void BuildCoreConfiguration(CoreConfiguration::Builder *builder)
Definition: grpc_plugin_registry.cc:109
grpc_core::CoreConfiguration::Reset
static void Reset()
Definition: core_configuration.cc:96
Builder
struct Builder Builder
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:68
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
thread
static uv_thread_t thread
Definition: test-async-null-cb.c:29
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:04