Skip to content

[CODE HEALTH] Fix clang-tidy narrowing-conversions warnings in tests#3987

Open
mateenali66 wants to merge 3 commits intoopen-telemetry:mainfrom
mateenali66:fix/3978-narrowing-conversions-tests
Open

[CODE HEALTH] Fix clang-tidy narrowing-conversions warnings in tests#3987
mateenali66 wants to merge 3 commits intoopen-telemetry:mainfrom
mateenali66:fix/3978-narrowing-conversions-tests

Conversation

@mateenali66
Copy link
Copy Markdown

Fixes #3978

applied static_cast at the narrowing point in three test files:

  • exporters/otlp/test/otlp_metrics_serialization_test.cc (3 sites) -- cast the size_t loop index when calling protobuf data_points(int) accessors.
  • sdk/test/metrics/aggregation_test.cc (2 sites) -- cast size_t max_buckets_ in the ternary branches where the result is assigned to int. kept the lvalue type as-is because test_merge lambda takes int expected_max_buckets and the values here are small test constants.
  • sdk/test/metrics/metric_test_stress.cc (3 sites) -- cast hardware_concurrency() (unsigned) and the uint64_t bucket counts/totals when accumulating into int64_t.

also decremented clang-tidy warning limits by 8.

note: #3985 (misc-use-internal-linkage) is also open against the same workflow file. whichever merges second will need a trivial rebase of the warning_limit numbers.

keeping as draft until clang-tidy CI confirms the new limits.

Changes

  • Fix clang-tidy cppcoreguidelines-narrowing-conversions warnings in tests.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

Apply static_cast at the narrowing site in three test files:

- otlp_metrics_serialization_test.cc: cast loop index when calling
  protobuf data_points(int) accessors (3 sites).
- aggregation_test.cc: cast size_t max_buckets_ on ternary branches
  where the lvalue is declared int (2 sites).
- metric_test_stress.cc: cast hardware_concurrency() result and the
  uint64_t bucket counts/totals used for int64_t accumulation (3 sites).

Decrement clang-tidy warning limits by 8 to match the removed unique
warnings.

Fixes open-telemetry#3978

Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
@mateenali66 mateenali66 marked this pull request as ready for review April 10, 2026 20:39
@mateenali66 mateenali66 requested a review from a team as a code owner April 10, 2026 20:39
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.18%. Comparing base (37a57da) to head (90dbe32).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3987   +/-   ##
=======================================
  Coverage   90.18%   90.18%           
=======================================
  Files         230      230           
  Lines        7299     7299           
=======================================
  Hits         6582     6582           
  Misses        717      717           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@dbarker dbarker left a comment

Choose a reason for hiding this comment

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

Thanks for the cleanup! Just some minor optional nitpicks

@@ -416,8 +416,8 @@ TEST(Aggregation, Base2ExponentialHistogramAggregationMerge)
const int expected_scale =
aggr_point.scale_ < default_point.scale_ ? aggr_point.scale_ : default_point.scale_;
const int expected_max_buckets = aggr_point.max_buckets_ < default_point.max_buckets_
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit - better to fix the type of the test variables to match those compared

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

addressed in the latest commit. changed expected_max_buckets to size_t and updated the test_merge lambda parameter to match, so no cast needed.

Addresses review nit on open-telemetry#3987. max_buckets_ is size_t on the
aggregation point data, so declaring expected_max_buckets as size_t
and updating the test_merge lambda parameter to match eliminates the
narrowing at the source rather than casting it away.

Signed-off-by: Mateen Anjum <mateenali66@gmail.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.

[CODE HEALTH] clang-tidy cppcoreguidelines-narrowing-conversions warnings in tests

2 participants