Skip to content

[CODE HEALTH] Move metrics storage test fixtures into anonymous namespace - #4286

Merged
marcalff merged 2 commits into
open-telemetry:mainfrom
thc1006:codehealth/metrics-test-fixtures-4196
Jul 24, 2026
Merged

marcalff merged 2 commits into
open-telemetry:mainfrom
thc1006:codehealth/metrics-test-fixtures-4196

Conversation

@thc1006

@thc1006 thc1006 commented Jul 24, 2026

Copy link
Copy Markdown
Member

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 lowering warning_limit to 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 identical WritableMetricStorageTestFixture, and all link into a single //sdk/test/metrics:all_tests binary. 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.h to de-duplicate it; happy to take that direction instead if preferred.

Verification

@thc1006
thc1006 requested a review from a team as a code owner July 24, 2026 02:02
Copilot AI review requested due to automatic review settings July 24, 2026 02:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…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
thc1006 force-pushed the codehealth/metrics-test-fixtures-4196 branch from 43d7cb0 to 17b8157 Compare July 24, 2026 02:03
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.31%. Comparing base (5946e38) to head (212c551).

Additional details and impacted files

Impacted file tree graph

@@           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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcalff
marcalff merged commit de8fa51 into open-telemetry:main Jul 24, 2026
72 checks passed
@thc1006
thc1006 deleted the codehealth/metrics-test-fixtures-4196 branch July 24, 2026 15:04
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants