Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky BroadcastReceiverSystemInfoProvider test #1185

Merged

Conversation

0xnm
Copy link
Member

@0xnm 0xnm commented Dec 9, 2022

What does this PR do?

This change fixes a flaky failure:

BroadcastReceiverSystemInfoProviderTest > M read system info W register() {Lollipop}(BatteryStatus, int, int, boolean) > com.datadog.android.core.internal.system.BroadcastReceiverSystemInfoProviderTest.M read system info W register() {Lollipop}(BatteryStatus, int, int, boolean)[6] FAILED
    java.lang.AssertionError at BroadcastReceiverSystemInfoProviderTest.kt:153

It happens because of the Float to Int conversion in the following operations:

> in code (level * 100) / scale
> in test (level * scale) / 100

Since this conversion simply truncates the floating part we may end up loosing too much precision for the final comparison. This change instead of the truncation of the decimal part does a proper rounding.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm 0xnm requested a review from a team as a code owner December 9, 2022 11:02
@0xnm 0xnm force-pushed the nogorodnikov/fix-flaky-BroadcastReceiverSystemInfoProvider-test branch from 2627c92 to 981d8d6 Compare December 9, 2022 11:27
@codecov-commenter
Copy link

codecov-commenter commented Dec 9, 2022

Codecov Report

Merging #1185 (18942b2) into develop (b627277) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #1185      +/-   ##
===========================================
+ Coverage    82.27%   82.31%   +0.04%     
===========================================
  Files          353      353              
  Lines        11793    11794       +1     
  Branches      2006     2006              
===========================================
+ Hits          9702     9708       +6     
+ Misses        1477     1476       -1     
+ Partials       614      610       -4     
Impacted Files Coverage Δ
...rnal/system/BroadcastReceiverSystemInfoProvider.kt 97.83% <100.00%> (+0.05%) ⬆️
...android/log/internal/logger/TelemetryLogHandler.kt 71.43% <0.00%> (-14.29%) ⬇️
...d/v2/core/internal/storage/FileEventBatchWriter.kt 95.24% <0.00%> (-2.38%) ⬇️
...core/internal/system/DefaultAndroidInfoProvider.kt 83.02% <0.00%> (-1.89%) ⬇️
.../android/rum/internal/monitor/DatadogRumMonitor.kt 92.27% <0.00%> (-1.10%) ⬇️
...n/com/datadog/android/v2/core/SdkInternalLogger.kt 80.77% <0.00%> (ø)
...android/v2/core/internal/DatadogContextProvider.kt 81.54% <0.00%> (ø)
...android/v2/core/internal/net/DataOkHttpUploader.kt 94.52% <0.00%> (ø)
.../android/rum/internal/domain/scope/RumViewScope.kt 95.42% <0.00%> (+0.18%) ⬆️
.../kotlin/com/datadog/android/v2/core/DatadogCore.kt 90.32% <0.00%> (+0.46%) ⬆️
... and 4 more

@0xnm 0xnm force-pushed the nogorodnikov/fix-flaky-BroadcastReceiverSystemInfoProvider-test branch from 981d8d6 to 308e3bc Compare December 12, 2022 15:29
@0xnm 0xnm force-pushed the nogorodnikov/fix-flaky-BroadcastReceiverSystemInfoProvider-test branch from 308e3bc to 18942b2 Compare December 12, 2022 15:44
@0xnm 0xnm merged commit e676513 into develop Dec 12, 2022
@0xnm 0xnm deleted the nogorodnikov/fix-flaky-BroadcastReceiverSystemInfoProvider-test branch December 12, 2022 16:24
@xgouchet xgouchet added this to the 1.16.0 milestone Dec 13, 2023
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.

4 participants