-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[incubator-kie-issues#6118] Fix flaky tests in AccumulateTest #6119
Conversation
* Replaced Set with LinkedHashSet in extractUsedDeclarations to ensure a consistent order of declarations. * The unordered nature of Set caused Drools to fail compiling the generated Java file, leading to test failures. * This resolves the flaky behavior by maintaining the necessary order of arguments during rule compilation. Tests was failing when running with NonDex: AccumulateTest#testBindingOrderWithInlineAccumulateAndLists AccumulateTest#testInlineAccumulateWithAnd Signed-off-by: Yusen Wang <[email protected]>
Hey, how were you able to trace/target the issue in the |
This PR will also fix the flaky test detected at |
This PR will also fix the flaky tests detected at under module |
This PR will also fix flaky test detected at org.drools.model.codegen.execmodel.AccumulateTest.testAccumulateWithIndirectArgument under module drools-model/drools-model-codegen |
I've never seen any of those mentioned tests failing even once in my life. It is true that the values returned in that |
Hi @mariofusco, Thank you for taking the time to review and for your feedback. I’d like to provide more context on my exploration of the codebase. Since this is my first time exploring this project, please bear with me if I am misunderstanding anything. From my understanding, the
These two places iterate over the same HashSet, but due to the non-deterministic iteration order of HashSet, they can produce different orders during the same execution. For instance, while running above test cases, I observed that the arguments passed to D.on(var_result, var_$eSet) could be in the order (result, $eSet) or ($eSet, result)., which leads to the above compilation error message. Based on my understanding, iteration order in a HashSet is inconsistent in the same session itself , even within the same VM and even if the HashSet's contents aren't modified. Thank you again for your time to read through this follow up. |
This assumption isn't correct, or better isn't correctly formulated, and however it doesn't apply to the specific context where this issue has been reported. Let me explain. It is true that the iteration order of an HashSet is not deterministic, but this doesn't mean that it randomically changes at each and every iteration. In particular for 2 iterations of the same unchanged HashSet instance in the same JVM execution it is guaranteed that the iteration order will be the same (no matter what it is) and this is enough for the use case that you analyzed. I believe that this is a case that is not correctly covered by that NonIndex tool that you used, so maybe a problem that should be reported and fixed there.
As I wrote I've never seen this failure in any of the thousands of the test suite execution that I performed either on our CI environment or on my local machines. If you can reproduce it, this means that I'm wrong and I'd be glad to have a call so you could show me how to reproduce this issue. |
Hi @mariofusco , Thanks for the guidance!
Thanks for pointing this out. My previous assumption was incorrect. For this case, the 'relatively deterministic' of the 2 iterations is sufficient. I did some simple experiment TestingResearchIllinois/idoft#1273 (comment), and the reason that NonDex is making a 'false positive' for this case is because the two types of iterations being used: the Collection.forEach at code and Stream.forEach at code. Inherently, they are using different implementations: Stream API is using Splitereator and the 'normal' Collections forEach is using Iterator. Right now NonDex is not shuffling Stream and caused the 'mismatch' between the two iterations during one execution in this particular case. However, after reading some online posts and Javadoc for Stream API, I still have one unresolved question: should we expect Any insights on this would be greatly appreciated! Sorry for the confusion to you earlier. I really appreciate the time you take in responding. |
That's a really good question (to which I wasn't actually thinking) and the short answer is that I don't know. In general if a behaviour is not clearly stated in the contract of an API I assume that I cannot rely on it. However in this specific case I'd be very surprised if the |
Description
I encountered non-deterministic behavior while running the following tests using NonDex:
Steps to reproduce
NonDex: https://github.com/TestingResearchIllinois/NonDex
Run the tests with NonDex:
The error message shows:
Click to view
Proposed Solution
The issue occurs due to non-deterministic behavior in the LambdaConsequence generated by
MethodCallExpr
andConsequence
, where the execute() method’s parameters are passed in an inconsistent order. This causes Drools to fail to compile the generated Java file when running above test cases.The root cause lies in the
extractUsedDeclarations
method in theConsequence
object uses a Set to track and filter arguments, and this results the non-deterministic behavior.To fix this, I replaced the Set with a LinkedHashSet in the extractUsedDeclarations method to ensure consistent ordering of declarations during rule compilation.