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 test ParallelIterableTestCase#sumOfFloatConsistentRounding. #1706

Open
motlin opened this issue Sep 15, 2024 · 4 comments
Open

Fix flaky test ParallelIterableTestCase#sumOfFloatConsistentRounding. #1706

motlin opened this issue Sep 15, 2024 · 4 comments
Assignees

Comments

@motlin
Copy link
Contributor

motlin commented Sep 15, 2024

This test sometimes fails with a delta greater than the allowed delta.

[ERROR]   ParallelCollectListIterableTest>ParallelIterableTestCase.sumOfFloatConsistentRounding:894 Batch size: 1000 ==> expected: <5.0000000000000995> but was: <5.000000000000101>

The test:

    @Test
    public void sumOfFloatConsistentRounding()
    {
        FloatFunction<Integer> roundingSensitiveElementFunction = i -> (i <= 99995) ? 1.0e-18f : 1.0f;

        MutableList<Integer> list = Interval.oneTo(100_000).toList().shuffleThis();
        double baseline = this.getExpectedWith(list.toArray(new Integer[]{}))
                .sumOfFloat(roundingSensitiveElementFunction);

        for (Integer batchSize : BATCH_SIZES)
        {
            this.batchSize = batchSize;

            ParallelIterable<Integer> testCollection = this.newWith(list.toArray(new Integer[]{}));
            assertEquals(
                    baseline,
                    testCollection.sumOfFloat(roundingSensitiveElementFunction),
                    1.0e-15,
                    "Batch size: " + this.batchSize);
        }
    }
@IamLRBA
Copy link

IamLRBA commented Oct 24, 2024

@motlin , I think the test failure you're encountering in the ParallelIterableTestCase#sumOfFloatConsistentRounding is related to floating-point precision. The error message shows that the expected result is <5.0000000000000995>, but the actual result was <5.000000000000101>. This difference is very small and falls within a "flaky test" range
because it depends on how floating-point arithmetic is handled internally, which can vary slightly across platforms or when using parallel processing.

@IamLRBA
Copy link

IamLRBA commented Oct 24, 2024

Please assign me to this issue so that i can try and solve it.
Thanks!

@motlin
Copy link
Contributor Author

motlin commented Oct 24, 2024

Assigned to you @IamLRBA !

@IamLRBA
Copy link

IamLRBA commented Oct 24, 2024

Thank you @motlin

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

No branches or pull requests

2 participants