Skip to content

Commit 0b0a8dd

Browse files
Adam Cozzettezhangskz
authored andcommitted
Move LazilyBuildDependenciesTest into its own .cc file and CMake test binary
One of the test cases involves observing the lazy loading behavior of the generated descriptor pool. Since this pool is a global, it can be influenced by other unrelated tests, and whether the test succeeds or fails depends on the test ordering. Moving the test into its own binary ensures that it will pass regardless of test ordering. Fixes #21431. PiperOrigin-RevId: 752313710
1 parent a59988c commit 0b0a8dd

File tree

5 files changed

+503
-411
lines changed

5 files changed

+503
-411
lines changed

cmake/tests.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,26 @@ add_test(NAME full-test
175175
COMMAND tests ${protobuf_GTEST_ARGS}
176176
WORKING_DIRECTORY ${protobuf_SOURCE_DIR})
177177

178+
# This test involves observing and modifying the internal state of the global
179+
# descriptor pool, so it needs to be in its own binary to avoid conflicting
180+
# with other tests.
181+
add_executable(lazily-build-dependencies-test
182+
${lazily_build_dependencies_test_files}
183+
)
184+
185+
target_link_libraries(lazily-build-dependencies-test
186+
libtest_common
187+
libtest_common_lite
188+
${protobuf_LIB_PROTOBUF}
189+
${protobuf_ABSL_USED_TARGETS}
190+
${protobuf_ABSL_USED_TEST_TARGETS}
191+
GTest::gmock_main
192+
)
193+
194+
add_test(NAME lazily-build-dependencies-test
195+
COMMAND lazily-build-dependencies-test ${protobuf_GTEST_ARGS}
196+
WORKING_DIRECTORY ${protobuf_SOURCE_DIR})
197+
178198
if (protobuf_BUILD_LIBUPB)
179199
set(upb_test_proto_genfiles)
180200
foreach(proto_file ${upb_test_protos_files} ${descriptor_proto_proto_srcs})

pkg/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ gen_file_lists(
132132
"//upb:test_protos": "upb_test_protos",
133133
"//upb:test_srcs": "upb_test",
134134
"//src/google/protobuf:full_test_srcs": "protobuf_test",
135+
"//src/google/protobuf:lazily_build_dependencies_test_srcs": "lazily_build_dependencies_test",
135136
"//src/google/protobuf:test_proto_all_srcs": "protobuf_test_protos",
136137
"//src/google/protobuf:lite_test_srcs": "protobuf_lite_test",
137138
"//src/google/protobuf:lite_test_proto_srcs": "protobuf_lite_test_protos",

src/google/protobuf/BUILD.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,30 @@ cc_test(
15681568
],
15691569
)
15701570

1571+
cc_test(
1572+
name = "lazily_build_dependencies_test",
1573+
srcs = ["lazily_build_dependencies_test.cc"],
1574+
copts = COPTS,
1575+
deps = [
1576+
":any_cc_proto",
1577+
":cc_test_protos",
1578+
":descriptor_legacy",
1579+
":port",
1580+
":protobuf",
1581+
":test_textproto",
1582+
":unittest_proto3_arena_cc_proto",
1583+
"//src/google/protobuf/io",
1584+
"//src/google/protobuf/io:tokenizer",
1585+
"//src/google/protobuf/stubs",
1586+
"//src/google/protobuf/testing",
1587+
"//src/google/protobuf/testing:file",
1588+
"@abseil-cpp//absl/strings",
1589+
"@abseil-cpp//absl/strings:str_format",
1590+
"@googletest//:gtest",
1591+
"@googletest//:gtest_main",
1592+
],
1593+
)
1594+
15711595
cc_library(
15721596
name = "test_textproto",
15731597
testonly = True,
@@ -2353,13 +2377,20 @@ filegroup(
23532377
"*unittest.cc",
23542378
],
23552379
exclude = [
2380+
"lazily_build_dependencies_test.cc",
23562381
"lite_unittest.cc",
23572382
"lite_arena_unittest.cc",
23582383
],
23592384
),
23602385
visibility = ["//pkg:__pkg__"],
23612386
)
23622387

2388+
filegroup(
2389+
name = "lazily_build_dependencies_test_srcs",
2390+
srcs = ["lazily_build_dependencies_test.cc"],
2391+
visibility = ["//pkg:__pkg__"],
2392+
)
2393+
23632394
filegroup(
23642395
name = "lite_test_srcs",
23652396
srcs = [

0 commit comments

Comments
 (0)