[CODE HEALTH] Move metrics storage test fixtures into anonymous namespace - #4286
Merged
marcalff merged 2 commits intoJul 24, 2026
Merged
Conversation
…pace Wrap the WritableMetricStorage* fixtures in the four sync/async metric storage test files in an anonymous namespace to enforce internal linkage (clang-tidy misc-use-internal-linkage), resolving 7 warnings and lowering the warning_limit to 156/166. Part of open-telemetry#4196 / open-telemetry#2053. All four files define an identical WritableMetricStorageTestFixture and link into one //sdk/test/metrics:all_tests binary, so wrapping them in per-translation-unit anonymous namespaces as-is would make gtest see one suite name backing different types and abort ("Attempted redefinition of test suite"). Each shared fixture is therefore first renamed with a file-specific prefix (Async/Counter/Gauge/UpDownCounter) so the suites stay distinct, as gtest's own diagnostic suggests; the file-local fixtures keep their already-unique names. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
force-pushed
the
codehealth/metrics-test-fixtures-4196
branch
from
July 24, 2026 02:03
43d7cb0 to
17b8157
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4286 +/- ##
=======================================
Coverage 81.31% 81.31%
=======================================
Files 445 445
Lines 18859 18859
=======================================
Hits 15333 15333
Misses 3526 3526 🚀 New features to boost your workflow:
|
marcalff
approved these changes
Jul 24, 2026
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
Jul 25, 2026
Six misc-use-internal-linkage sites, continuing from open-telemetry#4217 and open-telemetry#4286. logger_test.cc had an anonymous namespace already, with TestLogger just above it and TestProvider just below, so the existing namespace is extended to cover both rather than adding two more. string_test.cc is the same shape: its namespace closed immediately before SplitStringTestFixture, so the closing brace moves to the end of the file. The two provider_test.cc files get a namespace around the test body. In the logs one that puts the deprecated-declaration pragma push and pop pair inside the namespace, which is fine since both ends stay on the same side of the boundary. Worth noting that api/test/logs holds two different classes both named TestProvider, in logger_test.cc and provider_test.cc. They are in the same Bazel package, so giving them internal linkage also removes a latent one definition rule hazard. Part of open-telemetry#4196 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
6 tasks
4 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Part of #4196. Moves the
WritableMetricStorage*test fixtures in the four sync/async metric storage test files into an anonymous namespace to enforce internal linkage (misc-use-internal-linkage), resolving 7 warnings and loweringwarning_limitto 156/166.The gtest suite-name collision
These four files (
async_metric_storage_test.cc,sync_metric_storage_{counter,gauge,up_down_counter}_test.cc) each define an identicalWritableMetricStorageTestFixture, and all link into a single//sdk/test/metrics:all_testsbinary. Wrapping them in per-translation-unit anonymous namespaces as-is would make gtest see one suite name backing four different types and abort at startup ("Attempted redefinition of test suite") — this is exactly what #4217 hit, which is why these files were deferred there.So each shared fixture is first renamed with a file-specific prefix (
Async/Counter/Gauge/UpDownCounter) so the suites stay distinct, as gtest's own diagnostic suggests. The file-local fixtures (WritableMetricStorageTestUpDownFixture,WritableMetricStorageTestObservableGaugeFixture,WritableMetricStorageDeltaMultiReaderTestFixture) already have unique names and are wrapped unchanged.An alternative would be to hoist the shared fixture into
sdk/test/metrics/common.hto de-duplicate it; happy to take that direction instead if preferred.Verification
sdk/test/metrics/*.cc, so the combinedall_testsbinary has no suite-name collision (verified by grep).warning_limitlowered 163/173 to 156/166 (7 resolved). This touches the samewarning_limitline as [CODE HEALTH] Fix remaining misc-override-with-different-visibility warnings #4280; whichever merges first, I will rebase the other.