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

Fixed Flaky Test in WindowTest.java #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fixed Flaky Test in WindowTest.java #1

wants to merge 1 commit into from

Conversation

Sitara-a
Copy link
Owner

@Sitara-a Sitara-a commented Sep 5, 2024

Description

The test simulatedMultithreadedProcessing in the test class com.cloudhopper.commons.util.windowing.WindowTest could fail if the same key is generated by two different threads.

Steps to reproduce

Run the test multiple times. The current logic to generate a key is:
Integer.valueOf(""+id+""+x);
Here id is a number between 0 and requestThreadCount-1
x is a number between 0 and requestsPerThread-1
However, this can generate duplicate keys in some scenarios. Eg- For id = 0, x = 26 -> Key is 26 and for id = 2, x = 6 -> Key is 26. This leads to a DuplicateKeyException being thrown.

Expected Behaviour

All tests should pass

Actual Behaviour

The test can fail if duplicate keys are generated.

Solution

The logic of defining a key is updated to - Integer.valueOf(""+id*requestsPerThread+""+x);
This way there are no duplicate keys generated.

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.

1 participant