[fix][test] Add Delta Tolerance in Double-Precision Assertions to Fix Rounding Flakiness #24972
+69
−68
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.
Fixes #24970
Motivation
The PR on my fork was already approved: LucasEby#11
Several tests in this suite compare double values directly using equality assertions. These assertions occasionally fail due to minor inaccuracies introduced by floating-point rounding and double-precision limitations in Java’s IEEE 754 representation. Such discrepancies are expected when performing arithmetic operations on floating-point numbers and can lead to flaky test behavior.
Modifications
A small tolerance (delta) of
1e-5was added to each double comparison. This delta is at least two orders of magnitude smaller than the smallest compared values, ensuring that it does not affect the logical correctness of the tests. The same delta is already used consistently in another method within the same test class. The tests remain the same, we are just being more careful about double precision issues when comparing values to avoid preventable flaky failures.Verifying this change
This change is already covered by existing tests, such as
org.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testNoOwnerLoadDataorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testEmptyTopBundlesLoadDataorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testRecentlyUnloadedBrokersorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testRecentlyUnloadedBundlesorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testSheddingExcludedNamespacesorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testBundlesWithIsolationPoliciesorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testBundlesWithAntiAffinityGrouporg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testTargetStdorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testSingleTopBundlesLoadDataorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testBundleThroughputLargerThanOffloadThresholdorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testZeroBundleThroughputorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testTargetStdAfterTransferorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testMinBrokerWithLowTrafficorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testMinBrokerWithLowerLoadThanAvgorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testMaxNumberOfTransfersPerShedderCycleorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testLoadBalancerSheddingConditionHitCountThresholdorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testRemainingTopBundlesorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testLoadMoreThan100org.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testHighVarianceLoadStatsorg.apache.pulsar.broker.loadbalance.extensions.scheduler.TransferShedderTest#testLowVarianceLoadStatsDoes this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: LucasEby#11