-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
review: test: Fixed 4 non-deterministic flaky tests #6084
base: master
Are you sure you want to change the base?
Conversation
…make them deterministic
6496e3c
to
4ea8692
Compare
…tDeclaredFields() to make it deterministic
Hey, thank you for your PR. I'm not sure if the tests are at fault or if the implementations are broken. For example the enum constants situation: the test asserts that substituting public enum AnEnumModel {
case1, case2;
} Now, the resulting enum must have Can you point out where exactly the order is lost in the underlying code? Similarly for the imports. There, the order isn't as important, but I think it is reasonable to expect (and we could also specify that in the Javadocs) that the order will match the order in the source code. In that case, I'd prefer having one separate Pull Request per problem. Regarding the |
Hi @SirYwell
I debugged further and found that for imports, the order is changing from JDTImportBuilder.java Root Cause : In If the order of imports is expected to be in a particular order, we may need to change the code in the JDTImportBuilder here. Otherwise, if we are okay with a nondeterministic order of the function, we can improve the test case as done in the PR. Please let me know what is the expected behaviour here so that I can proceed with that fix.
The given fix is for spoon.test.processing.ProcessingTest#testInitPropertiesWithWrongType test, where we are setting the fields through ProcessorProperties and then asserting on the fields.
In the given test, the assertions are expecting that the value of attribute aString will be set first, then the value of anInt will be set, which will throw SpoonException.
Hence, to fix this test case, we may have to remove the assertion on aString and anObject. Please let me know your views on it or if I can provide any more details. Post that, I'll proceed with the change in a separate PR as you suggested.
For the enumValues, I am still investigating. I have narrowed it down to function generateTargets in |
Hi @SirYwell , |
Hi, if you found the root cause for the enum value problem, this seems to be the most relevant one. |
Hi,
Or maybe we can change the code to:
This will test the behaviour of wrongDataType correctly irrespective of the order the fields are returned. Let me know your thoughts on this. |
What changes were proposed in this pull request?
Sorting the order of imports list variable and enums list variable in 4 flaky tests in order to make them deterministic. The assertions are written with an assumption that the list will always be in a particular predefined order, but that may not be the case. The PR contains fix for the below test cases to make them deterministic:
Why are the changes needed?
Multiple flaky tests were detected while trying to run the tests using the nondex tool. NonDex is a tool for detecting and debugging wrong assumptions on under-determined Java APIs.
Sample ERROR logs:
Reason for Failure
As mentioned above, the assertions assume that the list will always be in a particular predefined order, but that may not be the case. For eg, in test case : staticImports_ofNestedTypes_shouldBeRecorded, we have the following test case
The above code assumes that the first element of the list will be
InnerClass
which may not be true. This is because the imports is being set byJDTImportBuilder.java
class where the imports variable is implemented as HashSet. As per the javadocs, the order of elements is not maintained in HashSet.Hence, we sort the fields before asserting based on certain fields to make the order deterministic.
Steps to reproduce flakiness using nondex -
Please let me know if you have any questions or would like to discuss this further for any clarificaitions.